Fixed bug 3405 - Wrong default icon size on windows systems

Evgeny Vrublevsky

Original code in the video/windows/SDL_windowsevents.c registers obsolete WNDCLASS (not WNDCLASSEX). As the result only one icon size is used as the small and normal icons. Also original code doesn't specify required size of an icon. As the result when 256x256 icon is available, the program uses it as a default icon, and it looks ugly.

We have to use WNDCLASSEX and load icons with proper sizes which we can get using GetSystemMetrics.

Better idea. We could use the first icon from resources, like the Explorer does. Patch is included. It also correctly loads large and small icons, so it will look nice everywhere.
This commit is contained in:
Sam Lantinga 2016-10-01 13:14:51 -07:00
parent 86b4319d21
commit 7b0ccd32e5

View File

@ -1054,7 +1054,8 @@ HINSTANCE SDL_Instance = NULL;
int int
SDL_RegisterApp(char *name, Uint32 style, void *hInst) SDL_RegisterApp(char *name, Uint32 style, void *hInst)
{ {
WNDCLASS class; WNDCLASSEX wcex;
TCHAR path[MAX_PATH];
/* Only do this once... */ /* Only do this once... */
if (app_registered) { if (app_registered) {
@ -1076,19 +1077,24 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst)
} }
/* Register the application class */ /* Register the application class */
class.hCursor = NULL; wcex.cbSize = sizeof(WNDCLASSEX);
class.hIcon = wcex.hCursor = NULL;
LoadImage(SDL_Instance, SDL_Appname, IMAGE_ICON, 0, 0, wcex.hIcon = NULL;
LR_DEFAULTCOLOR); wcex.hIconSm = NULL;
class.lpszMenuName = NULL; wcex.lpszMenuName = NULL;
class.lpszClassName = SDL_Appname; wcex.lpszClassName = SDL_Appname;
class.hbrBackground = NULL; wcex.style = SDL_Appstyle;
class.hInstance = SDL_Instance; wcex.hbrBackground = NULL;
class.style = SDL_Appstyle; wcex.lpfnWndProc = WIN_WindowProc;
class.lpfnWndProc = WIN_WindowProc; wcex.hInstance = SDL_Instance;
class.cbWndExtra = 0; wcex.cbClsExtra = 0;
class.cbClsExtra = 0; wcex.cbWndExtra = 0;
if (!RegisterClass(&class)) {
/* 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"); return SDL_SetError("Couldn't register application class");
} }
@ -1100,7 +1106,7 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst)
void void
SDL_UnregisterApp() SDL_UnregisterApp()
{ {
WNDCLASS class; WNDCLASSEX wcex;
/* SDL_RegisterApp might not have been called before */ /* SDL_RegisterApp might not have been called before */
if (!app_registered) { if (!app_registered) {
@ -1109,8 +1115,10 @@ SDL_UnregisterApp()
--app_registered; --app_registered;
if (app_registered == 0) { if (app_registered == 0) {
/* Check for any registered window classes. */ /* Check for any registered window classes. */
if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) { if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
UnregisterClass(SDL_Appname, SDL_Instance); UnregisterClass(SDL_Appname, SDL_Instance);
if (wcex.hIcon) DestroyIcon(wcex.hIcon);
if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
} }
SDL_free(SDL_Appname); SDL_free(SDL_Appname);
SDL_Appname = NULL; SDL_Appname = NULL;