Archive for the ‘FoxPro’ Category.

FoxPro Program For Printing Labels – LblPrint

This is a very simple label printer application I wrote for work. I don’t have the code for download, because it’s a very specific application, and probably won’t work for you, but it does showcase some of the powerfull features of Foxpro.

Here is how it works:

The user enters a search term, then clicks the search button. The program connects to the Sql Server 2000 database, retrieves the data, and populates the data grid. The user then selects the record desired and the label preview is generated. On every record selection the preview is automatically generated. The user can then select a modifier by clicking on one of the radio buttons to the right of the preview container. On each change of the modifier the preview is automatically updated. The user then clicks the print button and the label is sent to the label printer and the cursor is automatically placed in the search box.

Prior to printing, the user can can select the desired printer and paper size using the Print Setup button. Being able to select or change printer settings is very important, because some of the users use this application through a terminal server session. The label printer is attached to their local workstation and gets mapped from the terminal server back to their PC when they log on. Since the name of the printer is not known until after the user logs on, it would be difficult to hardcode the printer in the report file. By being able to make printer changes at runtime, it makes it easy for the user to chooses his or her printer after they log on. They only do this the first time, as once the settings are changed, they are saved in the lbx file until the next time they need to be updated.

For more information on the reporting capabilities of VFP 9, please check out this great article:

Techniques for an alternative Report Preview UI

Also, take a look at the SYS(1037) function in the FoxPro help file.

Here are some screenshots of the program. (click to enlarge)

FoxPro Program For Sharing Files At Lanparties – UtFiles

I’ve had this app for a while. In fact, this was one of the very first apps I built in Foxpro. I haven’t posted it because I wanted to get it cleaned up and add in some of the new things I’ve learned.

It’s basically a file sorting utility that takes files from a specified source directory and its subdirectories, and places them in the destination’s subdirectories based on the file’s extension.

It was originally designed to be used with “Unreal Tournament”. At lanparties it is quicker and easier to start a new match if everyone already has the files locally on their computers instead of having to download them from the game server when entering a new game. This utility makes it easy for everyone to get all the new maps/addons from a “lanparty” directory prior to starting the game.

The program can also be used for other occasions where files need to be organized in directories based on their extension. To know more download the program and give it a try. It has the ability to create a test directory, so you can change the mappings to search for any file type and then place it in one of the test directory’s subdirectory.

Click here to download the Windows 98 and up installer (5.2Mb)
Latest version 1.2.137

FoxPro Program For Extracting HTML – GetHtml

Another little program released. This program is for retrieving the HTML of a web page.

After experimenting with the West Wind Internet and Client Tools and then with my own version of a wininet.dll wrapper, I decided the easiest way was to use the WinHTTP service. I didn’t even know it existed until I found it on Calvin Hsia’s Weblog.

Below is the main code of the application. Look at the links provided in the readme for more information on the oHTTP object instantiated in the code.

Thisform.MousePointer = 11
Try
        Local oHTTP As "winhttp.winhttprequest.5.1"
        oHTTP=Newobject("winhttp.winhttprequest.5.1")
        oHTTP.Open("GET",Trim(Thisform.txtUrl.Value),.F.)
        oHTTP.Option(4) = 13056 && Ignore ssl errors
        && Lets look like IE
        oHTTP.SetRequestHeader("user-agent", ;
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows ;
                NT 5.2; .NET CLR 1.0.3705;)")

        oHTTP.Send()

        Thisform.txtHtml.Value = oHTTP.ResponseText
        Thisform.txtHeaders.Value = oHTTP.GetAllResponseHeaders
Catch To ex
        Thisform.txtHtml.Value = ex.Message
Finally
        Thisform.MousePointer = 0
Endtry

Click here to download the Windows 2000sp3 and up installer (5.2Mb)
Latest version 1.0.47

FoxPro Program For Testing SMTP Servers – SmtpTester

Ok…so here it is…the first of hopefully many applications you can download.

The idea to create this app came to me while I was trying to troubleshoot my uncle’s program that wouldn’t connect to his smtp server. His application is in VB6 and he uses it to send out emails from a list of addresses in an Access database. After he switched isps he could no longer get it to work since the new isp requires him to authenticate before being able to send mail. I didn’t know all the inner workings of communicating with an smtp server, but I was able to figure out that we needed to send the auth command and then in some way the username and password. Not having enough time to fix it I went home later that evening and started researching. To make it more interesting I decided to create a little tool that I could use to learn with as well as use later.

I decided to use Foxpro to develop the program for two main reasons. First, I’ve only been using it for about a year, so I needed the practice. Second, I wanted to develop an application that you wouldn’t normally see written in Foxpro. Most Foxpro apps, at least from what I can tell so far, are data driven applications. Many smaller companies out there tend to use Foxpro because it is relatively inexpensive, yet extremely flexible and super fast, especially when it comes to dealing with data. I also hope that by developing these little tools, I can help make people more aware that Foxpro is out there and can be used for a variety of projects.

Click here to download the Windows 98 – XP installer (5.2Mb)
Latest version 1.2.301

_Shortcutmenu Fix for ctl32_gripper

Update 09/10/2007: Per Carlos’s comment below, please note this fix is no longer needed.

In developing some of my Foxpro apps, I discovered that there is no built-in way of putting a gripper in the lower right-hand corner of my forms. Luckily, the wonderful foxpro community has a fix for this. In fact, there are several fixes, but the one I like the most is Carlos Alloatti’s ctl32_gripper.

Carlos’s control works very well, and his attention to detail make this custom control work and look just as if it were an original Foxpro control. I did, however, come across a little problem in my forms with my own custom controls not behaving correctly when I used the gripper control.

As many Foxpro developers do, I like to subclass the native Foxpro controls and create my own. Makes things easier when I want to make an app-wide change and I also like to add a few enhancements. For example, on the textbox control, I like a right click menu for cut, copy, and paste. In the “RightClick” event of the textbox, using the “_menu.vcx” Foxpro Foundation Class, I use some code to dynamically generate a popup menu. Unfortunately, herein lies the problem with the gripper control.

When I compile and run my app everything seems to work just fine, except when you go to invoke the right-click menu, it doesn’t always show up on the first click. It usually takes a few clicks before it comes up. When I run the program within the Foxpro IDE I get a similar behavior and I also get an error. The program errors out and the error routine shows the problem is on this line ” lnMRow=MAX(MROW(),0) ” in the “activatemenu” method of the “_shortcutmenu” class.

I know from looking at the code that the gripper class is intercepting the “WM_NCHITTEST” message of the form, so I know it has something to do with the code in the event handler for this message somehow interfering with the MROW() and MCOL() functions. While I’m not sure why this is happening, I have found a way around it that seems to work rather well.

I modified the code in the “activatemenu” method of the “_shortcutmenu” class as follows:

Original _shortcutmenu code:

lnMRow=MAX(MROW(),0)
lnMCol=MAX(MCOL(),0)

Modified _shortcutmenu code:

Local laMouseInfo(4)
AMouseObj(laMouseInfo,1)
lnMRow=MAX(laMouseInfo(4)/FONTMETRIC(1),0)
lnMCol=MAX(laMouseInfo(3)/FONTMETRIC(6),0)

If you know of a better solution or have more information on this please leave a comment.