[gens-sdl] Set the window icon on Windows.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 6 Sep 2015 18:31:42 +0000 (14:31 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 6 Sep 2015 18:31:42 +0000 (14:31 -0400)
This uses Win32 API to set the window class icon to the application
icon from the Win32 resource section in the executable.

TODO: Non-Windows icons.

src/gens-sdl/SdlGLBackend.cpp
src/gens-sdl/SdlSWBackend.cpp

index 1eacbdf..17328f8 100644 (file)
@@ -29,6 +29,9 @@ using LibGens::MdFb;
 // System byte order.
 #include "libcompat/byteorder.h"
 
+#include <SDL.h>
+#include <SDL_syswm.h>
+
 // GL_UNSIGNED_INT_8_8_8_8_REV is needed for native byte-order on PowerPC.
 // When used with GL_BGRA, it's effectively the same as GL_ARGB.
 #if SYS_BYTEORDER == SYS_BIG_ENDIAN
@@ -37,6 +40,12 @@ using LibGens::MdFb;
 #define SDLGL_UNSIGNED_BYTE GL_UNSIGNED_BYTE
 #endif
 
+// Windows icon.
+#ifdef _WIN32
+#include <windows.h>
+#include "win32/gens-sdl.h"
+#endif
+
 namespace GensSdl {
 
 SdlGLBackend::SdlGLBackend()
@@ -62,6 +71,21 @@ SdlGLBackend::SdlGLBackend()
                m_winW, m_winH,
                SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
 
+       // TODO: Split icon setting into a common function?
+#ifdef _WIN32
+       // Set the window icon.
+       HICON hIcon = LoadIcon(GetModuleHandleA(nullptr), MAKEINTRESOURCE(IDI_GENS_APP));
+       if (hIcon) {
+               SDL_SysWMinfo info;
+               SDL_VERSION(&info.version);
+               if (SDL_GetWindowWMInfo(m_window, &info)) {
+                       SetClassLongPtr(info.info.win.window, GCL_HICON, (LONG_PTR)hIcon);
+               }
+       }
+#else
+       // TODO: Non-Windows icon.
+#endif
+
        // Create the OpenGL context.
        m_glContext = SDL_GL_CreateContext(m_window);
 
index d3c595f..6cba8ee 100644 (file)
 #include <cassert>
 
 #include <SDL.h>
+#include <SDL_syswm.h>
+
+// Windows icon.
+#ifdef _WIN32
+#include <windows.h>
+#include "win32/gens-sdl.h"
+#endif
 
 namespace GensSdl {
 
@@ -40,6 +47,21 @@ SdlSWBackend::SdlSWBackend()
                                SDL_WINDOWPOS_UNDEFINED,
                                320, 240, SDL_WINDOW_RESIZABLE);
 
+       // TODO: Split icon setting into a common function?
+#ifdef _WIN32
+       // Set the window icon.
+       HICON hIcon = LoadIcon(GetModuleHandleA(nullptr), MAKEINTRESOURCE(IDI_GENS_APP));
+       if (hIcon) {
+               SDL_SysWMinfo info;
+               SDL_VERSION(&info.version);
+               if (SDL_GetWindowWMInfo(m_window, &info)) {
+                       SetClassLongPtr(info.info.win.window, GCL_HICON, (LONG_PTR)hIcon);
+               }
+       }
+#else
+       // TODO: Non-Windows icon.
+#endif
+
        // Create a renderer.
        // TODO: Parameter for enabling/disabling VSync?
        m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_PRESENTVSYNC);