Saturday, May 26, 2007

Using the gold in the VFP Solution Samples

I often refer developers to the Solution Samples and the Fox Foundation Classes (FFC) to see how things can be accomplished with Visual FoxPro. I have read Doug Hennig's articles on mining the gold out of the FFC and sat in on his sessions on the same subject. I believe these two resources are under utilized by many Fox developers. I might not use the classes directly (although I have from time-to-time), but the concepts and fundamental code is all there for the taking. There is some really cool code in the samples.

This month I got to leverage a class I have wanted to use since seeing it in the VFP 8.0 beta, but have not had a reason to do so until this month. I am not sure who wrote the System Tray Icon class, but they did a spectacular job on it. As is documented in the class: this is pure magic with a combination of Windows API calls and the BINDEVENT() function.

The concept is simple: display an icon in the system tray (AKA: the Windows Taskbar Notification Area). The icon handles events for the double-click and right-click so the user can interact with the icon with an optional menu, or run a process, or display a form or report. Optionally you can inform the user of events or actions taken via a balloon tip and/or a tool tip.

Like all the VFP Solution Samples, the System Tray Icon class comes with a sample to demonstrate how you work with the class. I was able to study the solution sample and get the class operational in short order. The sample uses a form and has the system tray object dropped on the form. I did everything in code:

goSysTray = NEWOBJECT("SysTray", "SysTray.vcx")

goSysTray.IconFile = "Graphics\SystemTrayApplet.ico"
goSysTray.TipText = "Process Runner Status"
goSysTray.MenuText = "menus\SysTrayShortcut.mpr"
goSysTray.MenuTextIsMPR = .T.
goSysTray.MenuOffsetFromRight = 100

There are numerous ways to create a menu. I created a shortcut menu complete with icons. My menu starts and stops a Windows Service, opens a top-level form, and shuts down the system tray applet. My application has a CONFIG.FPW compiled in it (file not excluded) to ensure the VFP frame does not display, a FoxUser.DBF file is not created, and some general house cleaning is handled.

SCREEN = off
HELP = off
MVCOUNT = 1200
TITLE = Process Runner

Since the status form is a top-level form it gets displayed on the Windows Desktop and it looks like a professional application to the end users.

Once and a while I will surf through the Solution Samples and FFC (via the Component Gallery) to see what is there and to take a peek at the code if I have time. The reason is probably obvious: if a client calls me and asks me if I can do something like X and I have not done it before, but can recall seeing it in the Solution Samples or FFC, I can tell them it is feasible. In the case of this project, when the client asked if he could have an icon in the system tray to show a form with the status of his process running as a Windows Service I was able to say "sure, no problem."

If you are looking for the System Tray Icon solution sample just start up the Task Pane Manager, click on the Solution Samples, and look under the New in Visual FoxPro 8.0 grouping. I am not sure I would have been able to put this class together in a weeks worth of hours. Thanks to whoever put this together. You made me look real good to my client and saved him a bunch of development time and money he can use on other parts of his project.



Post a Comment

<< Home