Classic VB - How can I set my exe icon using a resource file?
Usually under most circumstances you can set an icon for one of your forms and use it as the executable's icon. However when you are not using a form in your project (classe(s) and module(s) only) you dont have the option of setting an executable icon from the Application Icon propert dropdown list (Fig. 1). There are two methods for setting an executable icon: Using a Resource File and using API code. Below are the steps for using a Resource File.
Fig. 1
So one way around this limitation is to use a resource file and embed an icon for your executable.
If you dont have the Resouce Editor AddIn loaded then you can load it by clicking on the AddIn menu > AddIn Manager ... (Fig. 2). Check the Loaded / Unloaded and Load at startup checkboxes.
Fig. 2
Then click on the Project menu > Add new Resource File ... and browse to the location where you would like to save the resource file to your file system. Once there give it a name and click OK. You will see a new folder located in your project explorer called "Related Documents" and it will contain the new resource file (Fig. 3).
Fig. 3
Once the resource file is added you need to bring up the Resource Editor so we can add an icon to it. Click the Tools menu > Resource Editor ... Then click on the Add Icon toolbar button (Fig. 4).
Fig. 4
Now we will want to browse and select an icon file to use as our executable icon (Fig. 5).
Fig. 5
You will see that there is now a new entry named "101" under the Icon folder (Fig. 6).
Fig. 6
We need to rename this entry ID by right clicking on it and clicking Properties (Fig. 7).
Fig. 7
Name the ID to "APPICON" and click Ok.
Fig. 8
We can see the new changes (Fig. 9).
Fig. 9
Now lets test it out by compiling our project into an executable. Make sure if you do use this method with a project with forms in it that there is no form selected in the Application Icon property. After compiling the executable we can see our executable file now makes use of our custom icon (Fig. 10).
Fig. 10
Enjoy!
Last edited by si_the_geek; Oct 9th, 2006 at 11:39 AM.
Re: Classic VB - How can I set my exe icon using a resource file?
My only problem with this method (and I think it should be pointed out) is that VB6's resource editor accepts icons with color depth upto 256 colors. So if you have icons with True colors (not to mention XP and Alphas) then this method is going to fail [unfortunately] - Resource Editor will throw an error "Invalid Icon File".
On the other hand you may assign True and even XP colors icons to form directly - Whether or not proper colors are shown could be another topic but at least VB form does accept those colors depths.
Last edited by si_the_geek; Oct 24th, 2006 at 10:17 AM.
Reason: merged replies
Re: Classic VB - How can I set my exe icon using a resource file?
When I first started programming in VB (albeit a few months ago) I couldn't figure out how to change the icons, so I used Resource Hacker to change the icon in the .exe. This process works fairly well as you don't have to face the colours restrictions that you do in VB 6.
Last edited by si_the_geek; Nov 9th, 2006 at 03:04 PM.
Re: Classic VB - How can I set my exe icon using a resource file?
i have a answer for this problem!
If you want to use more color depths Icons, you should not use VB resource editor to add those Icons, you can use 2 file RC.exe, RCDLL.dll to combile your own resource file, and then add this file to VB Project.
You can use those icon in the same way as VB resource editor's icon.