I'm building a GUI with some simple dialogs using raw Win32 API with pure C (no MCF). In one of those dialog I'd like to display a button with an icon (a small folder) instead of a text.
I prepared a .ico file with the proper size (16x16 pixel) and I proceeded as follow:
I've defined the icon resource in resource header file:
#define ICON_FOLDER 901
I've put the icon, called folder.ico, in the same folder of the resource script and I've loaded icon resource in it:
ICON_FOLDER ICON "folder.ico"
I've defined my button in the corresponding dialog resource specifying the
BS_ICON
style (MODEL_SEARCH
is the resource ID defined in the resource header too):CONTROL "", MODEL_SEARCH, "button", BS_PUSHBUTTON | BS_ICON | WS_TABSTOP | WS_VISIBLE | WS_CHILD, 300, 8, 18, 18
In the GUI code, when the dialog containing the button is built, I've tried to load the icon at the beginning of the dialog procedure and then tried to set the icon in the case
WM_INITDIALOG
using respectively the following two loines of code:HICON folderico=LoadIcon(NULL,MAKEINTRESOURCE(ICON_FOLDER));
and
SendMessage(GetDlgItem(hwnd,MODEL_SEARCH),BM_SETIMAGE, (WPARAM)IMAGE_ICON,(LPARAM)folderico);
It doesn't work, the button is displayed but it doesn't show the icon.
I tried to do some changes and for example if I use those two last line of code to set one of default icons, like for example the IDI_APPLICATION
one, the icon corresponding to IDI_APPLICATION
resource is properly shown.