how to put small icon in dialog box title

This is a discussion on how to put small icon in dialog box title within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone, I am trying to put an icon in a dialog box titlebar. The code I am using (unsuccessfully) ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    hellertown, pennsylvania
    Posts
    24

    how to put small icon in dialog box title

    Hello everyone,

    I am trying to put an icon in a dialog box titlebar. The code I am using (unsuccessfully) is as follows:

    case WM_INITDIALOG :
    hIconSmall =(HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_32), IMAGE_ICON,
    16, 16, 0);
    SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall) ;
    return TRUE ;

    This doesn't work. The LoadImage function returns a non-NULL value for hIconSm, but no icon appears in the titlebar. The .ico resource (IDI_32) is a 32x32 pixel icon resource. I did not show the lines, but hIconSmall is declared as a static HICON in the dialogproc.

    Any ideas?

    Mark Allyn

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You may not have your window styles for the dialog set up correctly in your resources...

    If memory serves you need WS_CAPTION and perhaps WS_SYSMENU for an icon to be displayed.
    When the dialog opens it should pick up the default icon for the application automatically.
    Last edited by CommonTater; 12-17-2011 at 12:41 PM.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Location
    hellertown, pennsylvania
    Posts
    24
    Hello CommonTater

    I had already put WS_CAPTION in the resource template. I added WS_SYSMENU, recompiled, but that didn't work. It appears from an Ollydbg session that the SendMessage() call isn't working. LoadImage() is doing its job, however.

    Regards,
    Mark

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok so try other window styles... WS_POPUP etc...

    You should not have to set the icon manually... it should pick up the first one out of resourses automatically. It may in fact be your failed SetIcon call that's stopping it from showing any icon at all... comment that out for now.

    Are you using a visual resource editor like ResEdit? If so you should be able to see the default icon when you test your dialog.
    Last edited by CommonTater; 12-17-2011 at 03:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog don't show background or title
    By Normac in forum Windows Programming
    Replies: 1
    Last Post: 08-13-2007, 11:58 AM
  2. Title and Icon On Window
    By matth in forum C++ Programming
    Replies: 0
    Last Post: 03-21-2005, 02:53 PM
  3. Small icon problem
    By fusikon in forum Windows Programming
    Replies: 2
    Last Post: 01-13-2003, 05:42 PM
  4. title bar icon
    By phil in forum Windows Programming
    Replies: 2
    Last Post: 09-05-2002, 07:31 AM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 05:43 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21