How to load a small system icon?

前端 未结 1 921
春和景丽
春和景丽 2020-12-17 21:34

I need to display 16x16 pixel icons for error/warning/information. Unfortunately both LoadIcon(0, IDI_*) and LoadImage(0, OIC_*, IMAGE_ICON, 16, 16, LR_SH

相关标签:
1条回答
  • 2020-12-17 22:08

    The problem is that when you do it this way you get a cached version of the icon, the first one that the system loaded. That will be the large sized icon, typically 32x32. It matters not what size you specify.

    What you can do is find the ID of the desired resource in user32.dll and use something like this:

    LoadImage(GetModuleHandle('user32'), MAKEINTRESOURCE(103), IMAGE_ICON,
        16, 16, LR_DEFAULTCOLOR);
    

    You would be better to call GetSystemMetrics(SM_CXSMICON) to get hold of the icon size rather than to hard code 16, but you probably already know that.

    I'm not sure where you get the resource IDs from for the resources in user32, or even if they is any guarantee that they will stay constant across different Windows versions. My guess is that they will because too many programs would break, but that's just pure guesswork.

    0 讨论(0)
提交回复
热议问题