Results 1 to 13 of 13

Thread: Icon for a Dialog box

  1. #1
    Guest

    Post

    Is there anyway to add an icon to a dialog box?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Huh?

    As an system menu icon for the dialogue, or as a picture in its client area?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    As a system menu icon.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use:
    Code:
    HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON);
    SendMessage(hWndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
    ...this should go in WinMain, so that you can use the hInstance value (although it's nearly always 0x400000 or something like that). Replace IDI_ICON with the resource ID of your icon.
    Use ICON_BIG to set the large icon.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Guest
    Thanks, that was exactly what i was looking for. You seem to know a bit, so heres another question...

    I have an about dialog, and i want to display the icon in the client area next to the text. How do i do that?

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In your About dialogue (within the Dialog Editor), insert a Picture, and set it to Icon. It will then allow you to choose the icon's ID from a combo box. (I hope)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Guest
    Yup that worked, thanks alot for the help!

  8. #8
    Guest
    Got another one for ya. How do i put an icon next to a menu item?

  9. #9
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    I don't know about VC++ but in VB the SetMenuItemBitmaps API function worked just fine(put bitmaps next to menu items) It should work in VC++ ,after all it's API.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  10. #10
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    First, you have to get the handle of the parent menu.
    If the menu item is in the System Menu (I haven't tried adding icons to this, but it might work), then use this to get the handle:
    Code:
    HMENU hMenu = GetSystemMenu(hWndOfTheWindowWithTheMenuToWhichYouWantToAddIcons, FALSE);
    If the menu item is in a "normal" menu, then first you should use GetMenu to get the handle of the menu bar, and then GetSubMenu to get the specific menu in the menu bar.
    You start the count with zero. (Aka zero-based counting)
    For example, if your menu bar looks like this:

    File Edit View Help

    Then the position of the File menu is zero, the position of the Edit menu is one, View is two, and Help is three.
    Simple enough?
    Code:
    HMENU hMenu = GetMenu(hWndOfTheWindowWithTheMenuToWhichYouWantToAddIcons);
    hMenu = GetSubMenu(hMenu, nTheZeroBasedPositionOfTheMenuInTheMenuBar);
    
    if(hMenu == NULL) {
        // There is no menu with that position
    }
    Now, after you used one of the above two methods to get the menu handle, you should load a bitmap, and set the bitmap to the menu item.
    This is done with a call to SetMenuItemBitmaps.
    Again, the position is zero-based:
    If you picked the File menu, and its contents are New, Open, Save, Exit, then New is zero, Open is one, etc.
    Code:
    HBITMAP hBitmap = // Some bitmap-loading routine goes here...
    // The bitmap size should be 13x13 pixels.
    // Well, it usually is 13x13... The exact size is:
    // GetSystemMetrics(SM_CXMENUCHECK) x GetSystemMetrics(SM_CYMENUCHECK)
    
    BOOL bSuccess = SetMenuItemBitmaps(hMenu,
        nTheZeroBasedPositionOfTheMenuItemInTheParentMenuWhichYouShouldAlreadyHaveSelected,
        MF_BYPOSITION, hBitmap, hBitmap);
    TIP: Use different variable names.

    If you want different bitmaps depending on the check state of the menu item, you can load two bitmaps, and then instead of hBitmap, hBitmap use hBitmapToUseWhenItIsNormal, hBitmapToUseWhenItIsChecked.
    Or something like that.

    Then, you can test the bSuccess variable. If it is TRUE, then the function succeeded. If it is FALSE, then there's an error.
    To get extended error information, call GetLastError.

  11. #11
    Guest
    Thanks for all the help Yonaton, but i cant seem to get it to work. Does anyone have any sample projects?

  12. #12
    Guest
    Ok, i got it working now. But it changes color when the mouse moves over it. If you look at the icons in the menus in VC++ they dont change color. How do i do that?

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You'd need to use owner-drawn menus for that - look in the Platform SDK for the details. Also, V(ery) has some VB code to do this - look at that, and then you can transfer it to C++.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width