How to install HICON in a window (.ICO with multiple sizes)?

I would like to define a Win32 window application icon, for example. by calling SetClassLongwith GCL_HICONand passing the handle to the icon (see SetClassLong Function on MSDN).

This works fine, but I did not understand how to load the icon (from the ICO file) in order to preserve all available sizes (for example, 16x16, 32x32, 48x48 and a full-size PNG icon). When I load the icon file through LoadImageinto memory, in order to receive HICON, I must indicate what size I want (see My answer to the corresponding question ).

My ICO file contains a small image that should be used as a window icon (upper left corner of the title bar) and was designed as very clear, but also larger options that should be displayed in the Alt-Tab dialog, but ...

  • Downloading the 16x16 icon shows the correct icon in the title bar, but of course the ugly stretched version when I Alt-Tab. And the one that appears in the taskbar is also not very good.

  • Downloading the 48x48 icon shows a nice icon when I Alt-Tab, but the icon displayed in the title bar is blurry, as this is a smaller version of the 48x48 icon.

    / li>

Is there a way to tell Windows that my Windows has a multi-sized icon? Is there an obvious API that I skipped?

+3
3

GCL_HICON "" , GCL_HICONSM ( 32x32 16x16, GetSystemMetrics SM_CXICON SM_CXSMICON, ( LR_DEFAULTSIZE to LoadImage 0))

+2

.ICO . HICON . LR_DEFAULTSIZE, - , .ico , .

, .

HICON hicon = LoadImage(NULL, "filename.ico", IMAGE_ICON, 
                        0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);

.

.ico , , . ICON. , LoadIcon/LoadImage ICON, . , HICON. , , LookupIconIdFromDirectory

, GetIconInfo HICON, ICONINFO.

typedef struct _ICONINFO {
    BOOL fIcon;
    DWORD xHotspot;
    DWORD yHotspot;
    HBITMAP hbmMask;
    HBITMAP hbmColor;
} ICONINFO;
+4

.ico PNG- 256x256, Windows , :

var assembly = typeof (Xyz).Assembly;
var stream   = assembly.GetManifestResourceStream ("Foo.Resources.Form.ico");
var icon     = new System.Drawing.Icon (stream);

form.Icon = icon;

Form.ico, Resources , Foo , Windows 32x32 Alt-Tab 16x16 .

, PNG WinForms Form.Icon...

+1

Source: https://habr.com/ru/post/1732135/


All Articles