使用WIN32 API设置没有资源的程序图标 [英] Setting program icon without resources using the WIN32 API
问题描述
我正在使用Visual Studio的快速版本。因此,使用函数调用MAKEINTRESOURCE是不成问题的。我尝试通过覆盖getAdditionalClassInfo函数来设置应用程序图标。
I am working with the express version of Visual Studio. Therefore, using functions calls to MAKEINTRESOURCE are out of the question. I am tryting to set the application icon by overriding the getAdditionalClassInfo function.
WNDCLASSW *Robot::getAdditionalClassInfo(void) const {
WNDCLASSW *wc = Window::getAdditionalClassInfo();
HANDLE hIcon = LoadImage(NULL, L"imagepath/image.png", 32, 32, LR_LOADFROMFILE);
wc->hIcon = .....;
return wc;
}
有没有人知道如何设置此图标而不使用资源? p>
Does anyone know how I can set this icon WITHOUT using a resource?
推荐答案
我的建议,如果你想使用PNG,并能够改变图标,就是使用FreeImage加载它。然后你可以使用FreeImage将它很容易地转换为一个标准的HBITMAP。
My suggestion, if you'd like to use PNGs, and be able to change the icon, is to use FreeImage to load it. Then you can use FreeImage to convert it to a standard HBITMAP fairly easily.
如果你使用一个实际的图标文件,你可以做以下一旦窗口已创建:
If you're fine with using an actual icon file, you can do the following once the window has been created:
HANDLE hIcon = LoadImage(0, _T("imagepath/image.ico"), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
if (hIcon) {
//Change both icons to the same icon handle.
SendMessage(hwnd, WM_SETICON, ICON_SMALL, hIcon);
SendMessage(hwnd, WM_SETICON, ICON_BIG, hIcon);
//This will ensure that the application icon gets changed too.
SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_SMALL, hIcon);
SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_BIG, hIcon);
}
您可以从 getAdditionalClassInfo
并将其设置为 hIcon
。
You can likely call the similar function from within your getAdditionalClassInfo
and setting it to the hIcon
.
这篇关于使用WIN32 API设置没有资源的程序图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!