Company logo

FOXSTUFF

Advice, tips, techniques and downloads for Visual Foxpro developers.

Home | Contact

Do your application icons always show up?

Assigning an icon to a Visual FoxPro application is not as straightforward as you might think.

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.

Folders and shortcuts

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.

Figure 1

Figure 1: Use the Image Edit program to create multiple icons in one ICO file.

To create an icon at a different size, follow these steps:

  1. Open the ICO file in Image Edit.
  2. Use the Copy command to copy the existing image to the clipboard.
  3. Select Edit / New Image. Choose the target size, and select the "Stretch/shrink clipboard image" option. The design surface will be cleared.
  4. Select Paste from the Edit menu. The new image will appear. Edit it if necessary, then save it using the Save command (not Save As).

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:

[ImagEdit.Icon]
Win95=16,16,16

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.

More Visual FoxPro articles | Crystal Reports articles | Recommended books | Visual FoxPro consultancy | Contact us

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.