diff --git a/FL/Fl_Window.H b/FL/Fl_Window.H index d8ce9621e..b376c3b12 100644 --- a/FL/Fl_Window.H +++ b/FL/Fl_Window.H @@ -343,6 +343,7 @@ public: static void default_icon(const Fl_RGB_Image*); static void default_icons(const Fl_RGB_Image*[], int); + static void use_default_icon(); void icon(const Fl_RGB_Image*); void icons(const Fl_RGB_Image*[], int); @@ -351,7 +352,6 @@ public: // These 2 member functions break the driver model but are kept for back compatibility. // They are implemented in Fl_win32.cxx static void default_icons(HICON big_icon, HICON small_icon); - static void default_icons(); void icons(HICON big_icon, HICON small_icon); #endif diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx index f489fe89a..5748f4deb 100644 --- a/src/Fl_Window.cxx +++ b/src/Fl_Window.cxx @@ -322,6 +322,44 @@ void Fl_Window::default_icons(const Fl_RGB_Image *icons[], int count) { Fl::screen_driver()->default_icons(icons, count); } +/** Use default icons associated to the executable. + + Right now only for Windows where it picks the default icon from the + exe's resources. + + To do: pick default icon from inside a .app bundle on macOS. +*/ +void Fl_Window::use_default_icon() { +#ifdef _WIN32 + HICON *pbig, *psmall, big_icons[1], small_icons[1]; + wchar_t path[FL_PATH_MAX]; + + big_icons[0] = NULL; + small_icons[0] = NULL; + pbig = big_icons; + psmall = small_icons; + + if (default_big_icon != NULL) + DestroyIcon(default_big_icon); + if (default_small_icon != NULL) + DestroyIcon(default_small_icon); + + // use exe's/module's icon resource to set window default icons + if (GetModuleFileNameW(NULL, path, FL_PATH_MAX) == 0) + return; + if (ExtractIconExW(path, 0, pbig, psmall, 1) == 0) + return; + + default_big_icon = NULL; + default_small_icon = NULL; + + if (big_icons[0] != NULL) + default_big_icon = big_icons[0]; + if (small_icons[0] != NULL) + default_small_icon = small_icons[0]; +#endif +} + /** Sets or resets a single window icon. A window icon \e can be changed while the window is shown, but this diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index e60c50354..e0d5c9f4b 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -2430,35 +2430,6 @@ void Fl_Window::default_icons(HICON big_icon, HICON small_icon) { default_small_icon = CopyIcon(small_icon); } -void Fl_Window::default_icons() { - HICON *pbig, *psmall, big_icons[1], small_icons[1]; - wchar_t path[FL_PATH_MAX]; - - big_icons[0] = NULL; - small_icons[0] = NULL; - pbig = big_icons; - psmall = small_icons; - - if (default_big_icon != NULL) - DestroyIcon(default_big_icon); - if (default_small_icon != NULL) - DestroyIcon(default_small_icon); - - // use exe's/module's icon resource to set window default icons - if (GetModuleFileNameW(NULL, path, FL_PATH_MAX) == 0) - return; - if (ExtractIconExW(path, 0, pbig, psmall, 1) == 0) - return; - - default_big_icon = NULL; - default_small_icon = NULL; - - if (big_icons[0] != NULL) - default_big_icon = big_icons[0]; - if (small_icons[0] != NULL) - default_small_icon = small_icons[0]; -} - void Fl_WinAPI_Window_Driver::set_icons() { HICON big_icon, small_icon; diff --git a/test/sudoku.cxx b/test/sudoku.cxx index ee2c74c9e..8d14968d7 100644 --- a/test/sudoku.cxx +++ b/test/sudoku.cxx @@ -704,7 +704,7 @@ Sudoku::Sudoku() // Set icon for window #ifdef _WIN32 - Fl_Window::default_icons(); + Fl_Window::use_default_icon(); #else Fl_Bitmap bm(sudoku_bits, sudoku_width, sudoku_height); Fl_Image_Surface surf(sudoku_width, sudoku_height, 1);