Configuring a program icon without resources using the WIN32 API

I am working with an express version of Visual Studio. Therefore, the use of functions that call MAKEINTRESOURCE is out of the question. I am trying 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; } 

Does anyone know how I can install this icon WITHOUT using a resource?

+4
source share
1 answer

My suggestion, if you want to use PNG and be able to change the icon, is to use FreeImage to download it. Then you can use FreeImage to easily convert it to standard HBITMAP.

If you're comfortable using the actual icon file, you can do the following after creating the window:

 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); } 

You can probably call a similar function from your getAdditionalClassInfo and set it to hIcon .

+3
source

Source: https://habr.com/ru/post/1497795/


All Articles