Windows: Set window icon (#5486)
authoradrido <robots_only_adrido@gmx.com>
Thu, 30 Mar 2017 18:28:37 +0000 (20:28 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Thu, 30 Mar 2017 18:28:37 +0000 (20:28 +0200)
src/client/clientlauncher.cpp
src/porting.cpp
src/porting.h

index bdd16205fcc4e5fc776856dacf5b36955526519c..3ec7be7d99f81a0786d2f83816a41c07e713469d 100644 (file)
@@ -114,7 +114,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
 
        porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
 
-       porting::setXorgWindowIcon(device);
+       porting::setWindowIcon(device);
 
        /*
                This changes the minimum allowed number of vertices in a VBO.
index 023f0cca7d431d20377ee65564eec7a4d661c528..4786a2a390967183752eb8374475889a5a8f9a4a 100644 (file)
@@ -611,9 +611,9 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
 #endif
 }
 
-bool setXorgWindowIcon(IrrlichtDevice *device)
+bool setWindowIcon(IrrlichtDevice *device)
 {
-#ifdef XORG_USED
+#if defined(XORG_USED)
 #      if RUN_IN_PLACE
        return setXorgWindowIconFromPath(device,
                        path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
@@ -627,6 +627,36 @@ bool setXorgWindowIcon(IrrlichtDevice *device)
                setXorgWindowIconFromPath(device,
                        path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
 #      endif
+#elif defined(_WIN32)
+       const video::SExposedVideoData exposedData = device->getVideoDriver()->getExposedVideoData();
+       HWND hWnd; // Window handle
+
+       switch (device->getVideoDriver()->getDriverType()) {
+       case video::EDT_DIRECT3D8:
+               hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
+               break;
+       case video::EDT_DIRECT3D9:
+               hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
+               break;
+       case video::EDT_OPENGL:
+               hWnd = reinterpret_cast<HWND>(exposedData.OpenGLWin32.HWnd);
+               break;
+       default:
+               return false;
+       }
+
+       // Load the ICON from resource file
+       const HICON hicon = LoadIcon(
+               GetModuleHandle(NULL),
+               MAKEINTRESOURCE(130) // The ID of the ICON defined in winresource.rc
+       );
+
+       if (hicon) {
+               SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hicon));
+               SendMessage(hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(hicon));
+               return true;
+       }
+       return false;
 #else
        return false;
 #endif
index f5c7efcb2df3d05df5e0287511d8e79ecb77dcad..902547ea9790fb8b4af53892403465dd5016ddc8 100644 (file)
@@ -367,7 +367,7 @@ inline const char *getPlatformName()
 void setXorgClassHint(const video::SExposedVideoData &video_data,
        const std::string &name);
 
-bool setXorgWindowIcon(IrrlichtDevice *device);
+bool setWindowIcon(IrrlichtDevice *device);
 
 bool setXorgWindowIconFromPath(IrrlichtDevice *device,
        const std::string &icon_file);