Menu

Difference Ownerdraw Menu effects between v880 and v891

Help
kite
2021-10-20
2021-10-23
  • kite

    kite - 2021-10-20

    Same source, compiled by v880, owner draw menu is correct. But is not correct when compiled by v891.
    Is it bug of v891 ? Pls see screenshot.png in attachment, Print menu has sub menu. I can exclude submenu arrow in v880, but i cann't in v891. You can try my demo with v880/v891 at vs 2019 community edition.

     
  • kite

    kite - 2021-10-20

    Tested with v8.9.0, it is ok. It seem v8.9.1 bug.

     
  • kite

    kite - 2021-10-20

    Tested with v8.9.0, it is ok. Maybe bug of v8.9.1.

     
  • kite

    kite - 2021-10-20

    If I replaced wxx_gdi.h file using v8.9.1 in v8.9, sub menu arrow will not exclude from dc.
    It's ok when I switch back to v8.9.0.

     
  • David

    David - 2021-10-21

    Hi Kite,

    Thanks for your question.

    This is not a bug. It is a documented change to CDC. I refer you to the changes.txt file in the include folder. This file describes the changes made to the code for this version, including the changes to CDC.

    To update your code for version 8.9.1 add pDC.Detach() to the end of the CMainFrame::DrawItem as shown below. Detach is required here because the DrawItem function makes changes to the device context that need to be kept after the function ends.

    void CMainFrame::DrawItem(LPDRAWITEMSTRUCT lpdis, COLORREF bColor, COLORREF fColor, COLORREF hColor)
    {
        if (lpdis->CtlType != ODT_MENU)
            return;
    
        CDC pDC = lpdis->hDC;
    
        SetBkMode(pDC, TRANSPARENT);
        SetTextColor(pDC, fColor);
    
        MENUITEMDATA* pItemData = reinterpret_cast<MENUITEMDATA*>(lpdis->itemData);
        pDC.SolidFill(bColor, lpdis->rcItem);
    
        if ((lpdis->itemState & ODS_SELECTED) &&
            (lpdis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
        {
            //draw a blue background
            if (!pItemData->isSeparator)
            {
                SetTextColor(pDC, RGB(255, 255, 255));
                pDC.SolidFill(hColor, lpdis->rcItem);
            }
        }
    
        CString str = pItemData->itemText;
        //draw the caption of the menu item
        if (pItemData->isSeparator)
        {
            RECT rc = lpdis->rcItem;
            int h = rc.bottom - rc.top;
    
            rc.top = rc.top + h / 2;
            rc.bottom = rc.top + 1;
            pDC.SolidFill(fColor, rc);
        }
    
        pDC.TextOut(lpdis->rcItem.left + 8, lpdis->rcItem.top - 2, str);
    
        if (pItemData->hasSubmenu)
        {
            pDC.TextOut(lpdis->rcItem.right - 16, lpdis->rcItem.top - 2, L"+");
            pDC.ExcludeClipRect(lpdis->rcItem);
        }
    
        pDC.Detach();  // <-  Add this line
    }
    

    Best regards,
    David

     

    Last edit: David 2021-10-21
  • kite

    kite - 2021-10-23

    Hi, David

    Thanks for your advise.

     

Log in to post a comment.