Fixed bug 2841 - Hint to set resource id for window icon
authorSam Lantinga <slouken@libsdl.org>
Sun, 13 Aug 2017 14:15:52 -0700
changeset 112612d458a198021
parent 11260 f7abcb63e51e
child 11262 8e5441ab6c63
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.
include/SDL_hints.h
src/video/windows/SDL_windowsevents.c
     1.1 --- a/include/SDL_hints.h	Sun Aug 13 01:00:01 2017 -0400
     1.2 +++ b/include/SDL_hints.h	Sun Aug 13 14:15:52 2017 -0700
     1.3 @@ -222,6 +222,12 @@
     1.4  #define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN    "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
     1.5  
     1.6  /**
     1.7 + * \brief A variable to specify custom icon resource id from RC file on Windows platform 
     1.8 + */
     1.9 +#define SDL_HINT_WINDOWS_INTRESOURCE_ICON       "SDL_WINDOWS_INTRESOURCE_ICON"
    1.10 +#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"
    1.11 +
    1.12 +/**
    1.13   *  \brief  A variable controlling whether the windows message loop is processed by SDL 
    1.14   *
    1.15   *  This variable can be set to the following values:
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Sun Aug 13 01:00:01 2017 -0400
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Aug 13 14:15:52 2017 -0700
     2.3 @@ -28,6 +28,7 @@
     2.4  #include "SDL_syswm.h"
     2.5  #include "SDL_timer.h"
     2.6  #include "SDL_vkeys.h"
     2.7 +#include "SDL_hints.h"
     2.8  #include "../../events/SDL_events_c.h"
     2.9  #include "../../events/SDL_touch_c.h"
    2.10  #include "../../events/scancodes_windows.h"
    2.11 @@ -1070,6 +1071,7 @@
    2.12  int
    2.13  SDL_RegisterApp(char *name, Uint32 style, void *hInst)
    2.14  {
    2.15 +    const char *hint;
    2.16      WNDCLASSEX wcex;
    2.17      TCHAR path[MAX_PATH];
    2.18  
    2.19 @@ -1106,9 +1108,19 @@
    2.20      wcex.cbClsExtra     = 0;
    2.21      wcex.cbWndExtra     = 0;
    2.22  
    2.23 -    /* Use the first icon as a default icon, like in the Explorer */
    2.24 -    GetModuleFileName(SDL_Instance, path, MAX_PATH);
    2.25 -    ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
    2.26 +    hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON);
    2.27 +    if (hint && *hint) {
    2.28 +        wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
    2.29 +
    2.30 +        hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL);
    2.31 +        if (hint && *hint) {
    2.32 +            wcex.hIconSm = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
    2.33 +        }
    2.34 +    } else {
    2.35 +        /* Use the first icon as a default icon, like in the Explorer */
    2.36 +        GetModuleFileName(SDL_Instance, path, MAX_PATH);
    2.37 +        ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
    2.38 +    }
    2.39  
    2.40      if (!RegisterClassEx(&wcex)) {
    2.41          return SDL_SetError("Couldn't register application class");