c++winapidialogico

Setting icon in Win32 dialog to a default icon


I have an icon in a custom dialog box which I would like to be one of the icons which can simply be accessed via macros, such as MB_ICONERROR or MB_ICONINFORMATION. I know these are of course C(++) macros, so they can't just be writen into the .rc file, but I would like to display the file which they correspond to in my dialog. How can I do this? Thank you for your help.


Solution

  • The LoadIcon function is able to load those standard icons. E.g. LoadIcon(nullptr, IDI_ERROR) returns the same icon that MB_ICONERROR gives you in the standard message box.

    To display them in your own dialog box, use a static control with the SS_ICON style set, and then use the STM_SETICON message to assign the icon to the control.