In my code I am creating a dialog box with the DialogBox function.
In the dialog box callback I have this code:
case WM_INITDIALOG:
{
SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)(HICON)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON)));
return TRUE;
}break;
At some point in the past this worked just fine, and caused the program icon to be displayed in the upper left corner of the dialog box to the left of the caption.
The code is unaltered, but at some point is stopped working, possible when I upgraded to MingW 3.2.
Now nothing happens. I have of course checked that LoadIcon does return a valid icon handle, so that's not it.
This is frustrating, since the dialog box looks much better with the icon in place.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
msdn says:
WS_POPUPWINDOW
Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.
WS_SYSMENU
Creates a window that has a window menu on its title bar. The WS_CAPTION style must also be specified.
I think the icon you want is the window menu, and you need both WS_SYSMENU and WS_CAPTION for that; WS_POPUPWINDOW includes WS_SYSMENU and WS_POPUP, so you can probably use:
DS_CENTER | WS_CAPTION | WS_POPUPWINDOW
or
STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
why it worked before? possibly a bug in the old windres (or in the constant values)
Adrian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The double cast was just one of the stupid things I tried to correct the problem. I didn't think it would work (or even have a purpose), but I was getting desperate... :-)
For the record, the double cast wasn't there originally, and it isn't there now...
@Adrian:
Yes, you are probably correct that there was a bug in the older windres that caused my code (which also had a bug) to work. My error was actually concealed by the windres bug. :-)
Thanks to both of you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm frustrated.
In my code I am creating a dialog box with the DialogBox function.
In the dialog box callback I have this code:
case WM_INITDIALOG:
{
SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)(HICON)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON)));
return TRUE;
}break;
At some point in the past this worked just fine, and caused the program icon to be displayed in the upper left corner of the dialog box to the left of the caption.
The code is unaltered, but at some point is stopped working, possible when I upgraded to MingW 3.2.
Now nothing happens. I have of course checked that LoadIcon does return a valid icon handle, so that's not it.
This is frustrating, since the dialog box looks much better with the icon in place.
Holy cow!
This almost always happens to me when I ask a question. A fem minutes later I solve my own question...
Anyway, in case it can be of any use to anyone:
For some reason the style WS_POPUPWINDOW had to be added to the style of the dialogbox for the icon to show in the title bar.
I used to have this in the resource script:
STYLE DS_CENTER | WS_POPUP | WS_CAPTION
and the icon would show just fine.
Now I need to have this:
STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_POPUPWINDOW
to have the icon show in the title bar.
I don't know why, and I don't care, but it is a bit strange...
Out of interest why do you have this paramter?
(LPARAM)(HICON)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON))
You are casting a cast? Pointless? Try
(LPARAM)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON))
BlakJak :]
Blakjak, this is common in win32. It is for code clarity.
Kip
msdn says:
WS_POPUPWINDOW
Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.
WS_SYSMENU
Creates a window that has a window menu on its title bar. The WS_CAPTION style must also be specified.
I think the icon you want is the window menu, and you need both WS_SYSMENU and WS_CAPTION for that; WS_POPUPWINDOW includes WS_SYSMENU and WS_POPUP, so you can probably use:
DS_CENTER | WS_CAPTION | WS_POPUPWINDOW
or
STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
why it worked before? possibly a bug in the old windres (or in the constant values)
Adrian
@BlakJak:
The double cast was just one of the stupid things I tried to correct the problem. I didn't think it would work (or even have a purpose), but I was getting desperate... :-)
For the record, the double cast wasn't there originally, and it isn't there now...
@Adrian:
Yes, you are probably correct that there was a bug in the older windres that caused my code (which also had a bug) to work. My error was actually concealed by the windres bug. :-)
Thanks to both of you!