Skip to main content
GameDev.net gamedev.net
🔒 Locked

Icons

Started by evanofsky Feb 25, 2005 at 1:36 PM 9 replies 1k views
Original Post
evanofsky
evanofsky
I know how to make a .ico file, but how do I bind it to an application? Is there some kind of setting in the application that loads it, or is it in a separate file? Thankyou in advance!
Evil Steve
Evil Steve
You want a resource script. It basicly tells the compiler to include the icon in the exe. The first icon in the exe is used as its icon in Explorer, and you can access any icon in the exe for using as e.g. window icons.

How you add resources depends on what compiler you're using.
evanofsky
evanofsky
I'm usin' VC++.net. Is there any particular file name that the compiler includes, or do I add the script myself?
Evil Steve
Evil Steve
Right-click on your project in the solution explorer, and choose Add -> Add New Item, then choose "Resource Template", and select a name (e.g. "resource"), then click Open. Then in your new template, goto Edit -> Add Resource, and either double-click "Icon" to create a new one, or click "Import" to select a previously created one. Then rebuild your project, and your app should have your icon instead of the windows default one.
evanofsky
evanofsky
Alas, it didn't work. When I'm initializing the window and I'm loading the icon, should I put something different in? Right now it says this:

windowclass.hIcon = LoadIcon(0, IDI_APPLICATION);
Endurion
Endurion
As the first parameter of LoadIcon you need to insert the HINSTANCE handle you receive in WinMain. Alternatively you can use GetModuleHandle( NULL ) to get your HINSTANCE handle.

The HINSTANCE tells Windows from which process's resources to load the icon. If you put NULL there you can get some Windows standard GUI icons.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Evil Steve
Evil Steve
You can tell if the icon is in your exe, because the icon in explorer will have changed from the standard Windows icon to whatever icon you chose.
If the icon is in the exe, then as Endurion said, the first parameter should be your applications HINSTANCE.
evanofsky
evanofsky
Sorry guys, it's still not working... thanks for your patience. I set the first param to the HINSTANCE, and kept the second param at IDI_APPLICATION, which didn't work. The ID for my icon is IDI_ICON1, so I tried a few combinations with that, too. Like this:

LoadIcon(hInstance, IDI_ICON1);
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
LoadIcon(hInstance, "IDI_ICON1");

One thing is, I'm just taking the .exe from the "Debug" folder in my project folder. Is that why it's not working? I have the icon in the debug folder, too.
Evil Steve
Evil Steve
Did you add the icon file to the resource using the steps I posted? And does the exe in the debug folder have the default windows application icon or your own? If it's the default windows application icon, then the icon hasn't been saved with the exe.

When you use an icon resource, the icon is saved in the exe, so once the exe runs, it won't try to read the icon from the hard drive, it'll try to read it from the exe.
iMalc
iMalc
Why don't you use the new project wizard to create a new Hello World program (which already has icons present), and try to see what you are doing differently?
evanofsky
evanofsky
Okay, I give up. Thankyou for all your advice... may the force be with you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.