Setting program icon without resources using the WIN32 API

前端 未结 1 1656
被撕碎了的回忆
被撕碎了的回忆 2020-12-19 17:16

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

相关标签:
1条回答
  • 2020-12-19 17:29

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

    You can likely call the similar function from within your getAdditionalClassInfo and setting it to the hIcon.

    0 讨论(0)
提交回复
热议问题