Sign in to follow this  

Icon in about box won't display

This topic is 4339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All I need to do is add an icon to my program's about box. Something like this: Free Image Hosting at www.ImageShack.us So I create a dialog box using Visual Studio's editor, and add a 'picture' control. In the control's properties I change the type to 'icon' and the image field to IDI_FOHN (the id of the icon resource. Note that this same icon is also used for the my app's window and exe and works fine). In the editor, it displays correctly (I print-screened the above image from the editor). But at run-time the dialog always displays an exclamation icon instead. More weird is that if I add another icon to my resource script, and try to use that instead, this new icon won't display at all...? It must be something stupid I'm doing, but I've run out of ideas. Any wild guesses welcome :) Extract from resource.h:
#define IDC_STATICX  1056
#define IDI_FOHN     101
Extract from <program name>.rc (the about box's def)
IDD_ABOUT DIALOGEX 0, 0, 199, 151
style DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | 
    WS_SYSMENU
CAPTION "."
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,129,121,54,14,BS_CENTER | BS_VCENTER
    CONTROL         "",IDC_STATIC,"Static",SS_ETCHEDHORZ,49,61,137,1
    LTEXT           ".",IDC_STATIC,49,67,136,43
    ICON            IDI_FOHN,IDC_STATICX,14,18,21,20,SS_RIGHTJUST
    LTEXT           ".",IDC_STATIC,48,18,133,37
END
About box's calling code and proc:

DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);

...

BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam,
						   LPARAM lParam)
{
	switch(message)
	{
	case WM_INITDIALOG:
		// This code doesn't make any difference
		/*HICON hIcon;
		HWND  child;
		hIcon = LoadIcon(m_instance, MAKEINTRESOURCE(IDI_FOHN));
		child = GetDlgItem(hDlg, IDC_STATICX);
		SendMessage(child, BM_SETIMAGE, (WPARAM) IMAGE_ICON, 
			(LPARAM) hIcon);*/

		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDCANCEL:
		case IDOK:
			EndDialog(hDlg, 0);
			return TRUE;
		}
		break;
	}
	return FALSE;
}


Share this post


Link to post
Share on other sites
If your icon is not going to be changed, don't bother manually loading it: You may add an icon/bitmap as a resource then statically set the picture control's image to the resource ID. No code is required.

Share this post


Link to post
Share on other sites
First off LoadIcon is now replaced with LoadImage... (seem MSDN for LoadIcon)

Secondly, BM_SETIMAGE is for buttons, as far as I know you're trying to assign it to a static control so:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/staticcontrols/staticcontrolreference/staticcontrolmessages/stm_setimage.asp

Then it looks like your bitmap is a bigger then 16x16 pixels so you might need IMAGE_BITMAP instead. Another thing to try:

SendMessage(child, BM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM) hIcon);



change to:


SendMessage(hDlg, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP,
(LPARAM) hIcon);



Note the first and third param in SendMessage changed. See if that works. I'd recommend removing LoadIcon code just for your own sanity in the future. But I think the solution is in the link above.

Post back if you still cannot get it. I'm just getting to static controls in my Win32 wrapper.

Share this post


Link to post
Share on other sites
Swish! I've got it working now using STM_SETIMAGE.

To summarise what I've found then:

1. Setting an app's icon trivially works.
2. Adding an icon control using the resource editor alone, on the other hand, doesn't appear to work (in VS2003).
3. Trying to set the icon's image with BM_SETIMAGE...doesn't work.
4. Trying to set the icon's image by sending a message directly to the dialog box (the line of code Mike2343 wrote)...didn't work either.
5. What worked in the end was this:


BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
HICON hIcon;
HWND child;

hIcon = LoadIcon(g_instance, MAKEINTRESOURCE(IDI_FOHN));
child = GetDlgItem(hDlg, IDC_STATICX);

SendMessage(child, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM) hIcon);

return TRUE;
....





...and note that you need to change the default id for the icon from IDC_STATIC (for my icon I used IDC_STATICX for whatever reason) because IDC_STATIC is the id for controls that are not referenced in code.

Thanks everyone

Share this post


Link to post
Share on other sites

This topic is 4339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this