How do I set window titlebar icon and alt-tab icon in SDL2 / C++ / Visual Studio 2012 express program?

前端 未结 2 1963
时光取名叫无心
时光取名叫无心 2021-01-19 07:38

I have added a .rc file to my project with just the following:

IDI_MAIN_ICON          ICON          \"..\\\\..\\\\icon_artwork\\\\windows_icons\\\\project.         


        
2条回答
  •  时光取名叫无心
    2021-01-19 08:00

    As it stands, no. SDL for some reason eats the icon for the actual application window. However you can use WINDOWS specific code to fix this. Keep in mind that this is not portable.

    #if defined(_WIN32) && defined(GCL_HICON)
    void setWindowsIcon(SDL_Window *sdlWindow) {
        HINSTANCE handle = ::GetModuleHandle(nullptr);
        HICON icon = ::LoadIcon(handle, "IDI_MAIN_ICON");
        if(icon != nullptr){
            SDL_SysWMinfo wminfo;
            SDL_VERSION(&wminfo.version);
            if(SDL_GetWindowWMInfo(sdlWindow,&wminfo) == 1){
                HWND hwnd = wminfo.info.win.window;
                ::SetClassLong(hwnd, GCL_HICON, reinterpret_cast(icon));
            }
        }
    }
    #endif
    

提交回复
热议问题