How to change the cmfcmenubutton drop-down menu background color?

ZH Chan 66 Reputation points
2022-02-17T07:34:45.833+00:00

How to change the cmfcmenubutton drop-down menu background color?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,724 questions
{count} votes

Accepted answer
  1. Minxin Yu 11,666 Reputation points Microsoft Vendor
    2022-02-21T01:50:16.587+00:00

    Hi, @ZH Chan
    The background color can also be changed by setting the first SubMenu Properties> behavior> break.
    176204-image.png

    Snippet:

    CMenu* pMenu = new CMenu;  
    pMenu->LoadMenu(IDR_MENU1);  
    CMenu* pSubMenu = pMenu->GetSubMenu(0);  
    CBitmap bmp;  
    CBrush m_BKBrush;  
    bmp.LoadBitmap(IDB_BITMAP1);  
    m_BKBrush.CreateSolidBrush(0x00ffee/*color*/);  
    MENUINFO mnInfo;  
    memset(&mnInfo, 0, sizeof(MENUINFO));  
    mnInfo.cbSize = sizeof(MENUINFO);  
    mnInfo.fMask = MIM_BACKGROUND;  
    mnInfo.hbrBack = m_BKBrush;  
    ::SetMenuInfo(pSubMenu->m_hMenu, &mnInfo);  
    m_BKBrush.Detach();  
    m_menubutton.m_hMenu = pMenu->GetSubMenu(0)->GetSafeHmenu();  
    

    176139-image.png

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.