Grayed menu toolbar icons are not drawn on Vista and up in WM_DRAWITEM

121 views Asked by At

My application uses a so-called Internet Explorer-style menu bar, i.e. a toolbar that opens several drop down menus. hbmpItem is set to HBMMENU_CALLBACK so that my app can draw custom 24x24 icons on WM_DRAWITEM.

This is all working fine on Windows XP but on Vista (and up) no icons are drawn for grayed menu items. Menu items in normal state, however, are drawn fine on Vista too. But when an item is in grayed state, no icon gets drawn on Vista. Exception: When the user moves the mouse over a grayed item, the icon is drawn correctly. But all the other grayed items aren't drawn at all on Vista.

Does anybody have an idea what could be the reason for this behaviour?

Here is how I draw my icons on WM_DRAWITEM:

case WM_DRAWITEM: {
    DRAWITEMSTRUCT *lpdis = (DRAWITEMSTRUCT *) lParam;

    if(!lpdis) return 0;

    if(lpdis->CtlType == ODT_MENU) {

        struct menuinfo *mi = (struct menuinfo *) lpdis->itemData;
        int ricon;
        HICON hIcon;

        if(lpdis->itemState & ODS_GRAYED) {
            ricon = mi->grayedicon;
        } else {
            ricon = mi->icon;
        }

        if(!(hIcon = LoadIcon(hInstance_g, MAKEINTRESOURCE(ricon)))) return 0;

        DrawIconEx(lpdis->hDC,
            lpdis->rcItem.left - 16,
            lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 24) / 2,
            hIcon, 24, 24,
            0, NULL, DI_NORMAL);

        DestroyIcon(hIcon);         

        return 1;
    }

    return 0;   
    }

case WM_MEASUREITEM: {
    MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT *) lParam;

    if(!lpmis) break;

    lpmis->itemWidth += 24;
    if(lpmis->itemHeight < 24) lpmis->itemHeight = 24;
    return TRUE;    
    }

Thanks for your help!

UPDATE

Sometimes parts of the icon are drawn. Here is a screenshot: You can see that the icons for undo, copy, paste, and delete aren't drawn. The icon for cut is partially drawn (it should be a full pair of scissors but only the bottom half of the icon is actually drawn). The icon for redo is drawn correctly only because the mouse cursor is currently over it. As soon as the mouse cursor leaves the item, the icon will disappear immediately.

Screenshot

0

There are 0 answers