Carl Mark
Carl Mark

Reputation: 371

winapi c++ HICON

I use minGW and eclipse. And I made the HICON in this way:

case WM_CREATE:
{
...
hIcon = (HICON)LoadImage(NULL, "icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if(hIcon) { SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); }
else { MessageBoxW(hwnd, "ico not found", "ico not found", MB_OK | MB_ICONERROR); }
...
}

So in this way the .ico must be in the same folder as the .exe How can I build this .ico in to the exe?

Upvotes: 0

Views: 6086

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596582

Use an .rc file to add the .ico file to your executable's resources. Then when calling LoadImage(), get rid of the LR_LOADFROMFILE flag and specify the ID of your resource in the lpszName parameter instead of a filename. For example:

MY_ICON ICON "icon.ico"

.

case WM_CREATE:
{
...
hIcon = (HICON) LoadImage(GetModuleHandle(NULL), "MY_ICON", IMAGE_ICON, 32, 32, 0);
...
}

Upvotes: 5

Johnny Mnemonic
Johnny Mnemonic

Reputation: 3912

You can use resource files.

See here for more information: http://msdn.microsoft.com/en-us/library/zabda143(v=vs.71).aspx

Upvotes: 2

Related Questions