Fixed bug 2841 - Hint to set resource id for window icon Alexey Seems to be a missing functionality. I want to set an icon from RC file. I cant pass MAKEINTRESOURCE(X) string to SDL_RegisterApp() cause string returned by MAKEINTRESOURCE string is not actually a string and SDL_strlen will crash. Moreover LoadImage seems to be loading wrong icon size. LoadIcon seems to be fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index b9b1e3e..2b2fd49 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -222,6 +222,12 @@ extern "C" {
#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
/**
+ * \brief A variable to specify custom icon resource id from RC file on Windows platform
+ */
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"
+
+/**
* \brief A variable controlling whether the windows message loop is processed by SDL
*
* This variable can be set to the following values:
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index eca633b..bdc6814 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -28,6 +28,7 @@
#include "SDL_syswm.h"
#include "SDL_timer.h"
#include "SDL_vkeys.h"
+#include "SDL_hints.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_touch_c.h"
#include "../../events/scancodes_windows.h"
@@ -1070,6 +1071,7 @@ HINSTANCE SDL_Instance = NULL;
int
SDL_RegisterApp(char *name, Uint32 style, void *hInst)
{
+ const char *hint;
WNDCLASSEX wcex;
TCHAR path[MAX_PATH];
@@ -1106,9 +1108,19 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst)
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
- /* Use the first icon as a default icon, like in the Explorer */
- GetModuleFileName(SDL_Instance, path, MAX_PATH);
- ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
+ hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON);
+ if (hint && *hint) {
+ wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
+
+ hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL);
+ if (hint && *hint) {
+ wcex.hIconSm = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
+ }
+ } else {
+ /* Use the first icon as a default icon, like in the Explorer */
+ GetModuleFileName(SDL_Instance, path, MAX_PATH);
+ ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
+ }
if (!RegisterClassEx(&wcex)) {
return SDL_SetError("Couldn't register application class");