Loading an Icon [WinAPI]

Started by
1 comment, last by stenny 17 years ago
G'day[smile], I was wondering, how I could load and external Iconfile and use it as the Icon of my Application. I've got a file called 'Icon' in the same folder as the exe, but I don't know what exactly to use. I've tried something like: m_wcex.hIcon = LoadImage(m_hInst, "Icon", IMAGE_ICON, NULL, NULL, LR_LOADFROMFILE); But LoadImage returns a HANDLE, and I don't know how to use LoadIcon (and the msdn I should use LoadIcon). Also, I haven't got a clue what the extension of an icon is, and whether I need to use WNDCLASSEX.hIcon or WNDCLASSEX.hIconSm. Could someone help? -Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Advertisement
The extension for icons is .ico. To load an external icon using LoadImage(), you need to typecast the returned HANDLE to a HICON:

m_wcex.hIconSm = HICON(LoadImage(NULL,                                  "Icon.ico",                                  IMAGE_ICON,                                 GetSystemMetrics(SM_CXSMICON),                                                      GetSystemMetrics(SM_CXSMICON),                                 LR_LOADFROMFILE));

Also, the member hIcon specifies the icon for the class, whereas hIconSm determines the small icon used in the application's title bar.

Hope this helps.
Ok. Thanks, Mate!

-Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel

This topic is closed to new replies.

Advertisement