Use native window/taskbar icons on Windows

This used to be a feature before the accurate-portable split, I'm
just restoring it.

Previously, while the EXE itself had a unique icon, the window and
taskbar both used the generic 'small' icon, which the original EXE
only used for the window.

SDL2 gives us a way to assign separate icons to each, but it's a
little clunky: it's Windows-only, requires the icons be in .ico
format, and needs them to be embedded in the EXE as resource files.
Also, for some reason, SDL2 doesn't let us refer to them by name - we
have to use their numerical ID.
This commit is contained in:
Clownacy 2020-01-21 11:27:32 +00:00
parent ad9e3c3e3b
commit 976e2425fc
4 changed files with 24 additions and 2 deletions

View file

@ -221,7 +221,6 @@ set(RESOURCES
BITMAP/Credit18.bmp
CURSOR/CURSOR_IKA.bmp
CURSOR/CURSOR_NORMAL.bmp
ICON/ICON_MINI.bmp
ORG/Access.org
ORG/Anzen.org
ORG/Balcony.org
@ -277,6 +276,10 @@ else()
list(APPEND RESOURCES "BITMAP/pixel.bmp" "FONT/LiberationMono.ttf")
endif()
if(NOT WIN32)
list(APPEND RESOURCES "ICON/ICON_MINI.bmp")
endif()
if(FIX_BUGS)
target_compile_definitions(CSE2 PRIVATE FIX_BUGS)
endif()

View file

@ -58,8 +58,16 @@ BEGIN
END
END
0 ICON "ICON/0.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
0 ICON "ICON/0.ico"
1 ICON "ICON/ICON_MINI.ico"
#endif // Japanese resources
/////////////////////////////////////////////////////////////////////////////

View file

@ -193,6 +193,11 @@ int main(int argc, char *argv[])
RECT unused_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
#ifdef _WIN32
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON, "0");
SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "1");
#endif
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_Window *window;
@ -274,11 +279,13 @@ int main(int argc, char *argv[])
size_t resource_size;
SDL_RWops *rwops;
#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
rwops = SDL_RWFromConstMem(resource_data, resource_size);
SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
SDL_SetWindowIcon(window, icon_surface);
SDL_FreeSurface(icon_surface);
#endif
resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size);
rwops = SDL_RWFromConstMem(resource_data, resource_size);

View file

@ -32,7 +32,9 @@
#else
#include "Resource/FONT/LiberationMono.ttf.h"
#endif
#ifndef _WIN32
#include "Resource/ICON/ICON_MINI.bmp.h"
#endif
#include "Resource/ORG/Access.org.h"
#include "Resource/ORG/Anzen.org.h"
#include "Resource/ORG/Balcony.org.h"
@ -113,7 +115,9 @@ static const struct
#else
{"FONT", "FONT", rLiberationMono, sizeof(rLiberationMono)},
#endif
#ifndef _WIN32
{"ICON", "ICON_MINI", rICON_MINI, sizeof(rICON_MINI)},
#endif
{"ORG", "ACCESS", rAccess, sizeof(rAccess)},
{"ORG", "ANZEN", rAnzen, sizeof(rAnzen)},
{"ORG", "BALCONY", rBalcony, sizeof(rBalcony)},