Microsoft KB Archive/291569

= How To Associate a Custom Icon with a Formless Visual Basic Application =

Article ID: 291569

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q291569



SUMMARY
For Visual Basic applications that do not contain forms, you can still provide a custom icon for the executable. This article explains how you can add an icon resource to the project.



MORE INFORMATION
When you create a Visual Basic executable application, you can select an icon from one of the project's forms in the Icon drop-down list box on the Make tab of the Project Properties dialog box to use as the icon for the executable file. However, if there are no forms in the project, no icons are available in the drop-down list box of the Make tab. In this case, you can create a custom icon resource in your project. The compiler uses this resource as the icon for your executable file. If you include more than one icon, the compiler uses the icon whose letter appears first in the alphabet because it prioritizes alphabetically.

The following sample demonstrates how to provide a custom icon for a simple, formless Visual Basic EXE project. For this sample, you may select an icon from your system, or you can create your own. By default, Visual Basic 6.0 installs icons in the following folder:

C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\

To create your own icon, you can use a tool such as Image Editor, which is available from the Visual Basic 6.0 CD (Disk 1) or the Visual Studio 6.0 CD (Disk 3) at the following location:

\Common\Tools\VB\Imagedit\Imagedit.exe

Step-by-Step Example
 Create a new Visual Basic standard EXE project. Form1 is created by default. Right-click Form1 in the Project window, and then click Remove Form1 to remove the form from the project. Add a new standard module (Module1) to the project.  Paste the following code into the code window of Module1: Public Sub Main MsgBox &quot;Hello World&quot; End Sub  Select an icon from the list, or use Image Editor (or another appropriate tool) to create an icon file. To load the Visual Basic Resource Editor, follow these steps:  From the Add-Ins menu, click Add-In Manager.</li> Locate VB 6 Resource Editor in the list of available add-ins.</li> Double-click VB 6 Resource Editor to load the editor add-in.</li></ol> </li> From the Tools menu, click Resource Editor.</li> In the Resource Editor window, click Add Icon on the toolbar. (This button appears as a small gray square that is outlined in blue.)</li> Open the icon file that you created earlier.</li> By default, the icon is added with the name &quot;101&quot;. Right-click the icon resource that was just added, and then click Properties.</li> In the Id box, type APPICON to rename the icon resource, and then click OK.

NOTE: &quot;APPICON&quot; is just a suggested name for your resource. If you already have other, named icon resources, make sure that your executable icon begins with a letter that occurs later in the alphabet than the other icons. For example, if you have an icon that is named &quot;AAA&quot; and another that is named &quot;BBB&quot;, the compiler uses the one that is named &quot;AAA&quot; as your application icon.</li> From the File menu, click Make to compile the Visual Basic project.</li> In Windows Explorer, browse to the location where you compiled your executable file. Notice that the icon for the executable file is the icon that you selected in the Resource Editor.</li></ol>

<div class="references_section">