Consultancy and Programming
Advice, tips, techniques and downloads for Visual Foxpro developers.
Developers on our Visual FoxPro training courses sometimes say that they have trouble assigning icons to applications. They correctly set the _SCREEN.Icon property, but their custom icons still fail to appear. Here's why.
In current versions of Windows, application icons appear in four different places:
It is only the first two of these that are affected by the _SCREEN.Icon property. If you assign a value to the property, for example like this:
_SCREEN.Icon = "MyIcon.ICO"
then the image in MyIcon.ICO will replace the default icon in the title bar and on the taskbar. The default is the FoxPro logo if the application is running within VFP; it is the Windows logo if it is running from an EXE.
The same applies to icons that you assign to individual forms. By setting a form's Icon property, the designated image will appear in the form's title bar, and also in the minimized representation of the form within the main VFP window.
By the way, if you set a form's Icon property from within the Form Designer, the ICO file must exist at design time. If it does not, you will see an error message and the property will revert to its default value (even if it previously contained a valid non-default value). But if you set the property to a non-existent file from within your code, no error is generated; the setting is simply ignored.
To assign the icon that will appear in folder windows and as desktop shortcuts, a different technique is used. You need to go to the Project Information dialog (from the Project menu), select the Project tab, and enable the Attach Icon checkbox. An Open dialog will appear, from which you can select (and preview) the required ICO file. When you run the app from an EXE, it will display the icon you specify.
But that's not the end of the story. To display correctly, the ICO file must contain two separate copies of the icon. It needs a 16x16 image to display in folder windows (and also in the Start menu), and a 32x32 version for desktop shortcuts.
To find out what a given ICO file contains, open it in the Image Edit program that comes with VFP (see Figure 1). The drop-down list labeled Icon Image will tell you the sizes (and color depths) of the contained icons.
To create an icon at a different size, follow these steps:
If you are using VFP 3.0., you might have difficulties creating a 16x16 icon. If so, try adding these lines to ImagEdit.Ini, which is in the Windows directory:
As you can see, assigning icons to applications is not completely straightforward, but if you follow these steps, you should get it right every time.
Note added January 2006. Image Edit is no longer bundled with Visual FoxPro, but other icon editing utilities are readily available. We can particularly recommend Axialis Icon Workshop, which can easily produce ICO files containing the image sizes mentioned in this article.
Mike Lewis Consultants Ltd. January 1998. Revised January 2006.
FoxStuff is maintained by Mike Lewis Consultants Ltd. as a service to the VFP community. Feel free to download and use any code or components, and to pass around copies of the articles (but please do not remove our copyright notices or disclaimers).
The information given on this site has been carefully checked and is believed to be correct, but no legal liability can be accepted for its use. Do not use code, components or techniques unless you are satisfied that they will work correctly in your applications.
© Copyright Mike Lewis Consultants Ltd.