Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Change MenuBar & ToolBar Background Color

karhongkarhong Member Posts: 14
Hi, I wanted to ask is there any other ways to change the background color for MenuBar(whole line of menu bar, including menu item) and also Toolbar background to other colour rather than following window's color scheme ??

I've search for few days, the solution i found is either :
1. Define our own menu [refer to below's link which teaches us to do OwnerDrawMenu

http://www.codeguru.com/Cpp/controls/menu/article.php/c3721/

2. Change the window's settings [This is not really a good approach because it will force all other application to have the same colour]


Is there anyone of you able to find other solution rather than these 2 i stated??

Another question, if you tried to go for [1] solution, on that demo, it will only have the background change for menu items ONLY. For the right side of the MenuBar, the colour will keep on the default [which is gray]. Is there any ways to make the whole MenuBar[whole line] to have the colour that i preferred?

Any help would be appreciated..

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi, I wanted to ask is there any other ways to change the background
    : color for MenuBar(whole line of menu bar, including menu item) and
    : also Toolbar background to other colour rather than following
    : window's color scheme ??
    :
    : I've search for few days, the solution i found is either :
    : 1. Define our own menu [refer to below's link which teaches us to do
    : OwnerDrawMenu
    :
    : http://www.codeguru.com/Cpp/controls/menu/article.php/c3721/
    :
    : 2. Change the window's settings [This is not really a good approach
    : because it will force all other application to have the same colour]
    :
    :
    : Is there anyone of you able to find other solution rather than these
    : 2 i stated??
    :
    : Another question, if you tried to go for [1] solution, on that demo,
    : it will only have the background change for menu items ONLY. For the
    : right side of the MenuBar, the colour will keep on the default
    : [which is gray]. Is there any ways to make the whole MenuBar[whole
    : line] to have the colour that i preferred?
    :
    : Any help would be appreciated..
    :
    [color=Blue]
    There is a way #3: completely new custom made menu bar. However, it is a big implementation if you also need to do the popups. Just the bar is not that bad. But, then you free to do anything you want - any fancy stuff, gradients, etc.
    [/color]
  • karhongkarhong Member Posts: 14
    : : Hi, I wanted to ask is there any other ways to change the background
    : : color for MenuBar(whole line of menu bar, including menu item) and
    : : also Toolbar background to other colour rather than following
    : : window's color scheme ??
    : :
    : : I've search for few days, the solution i found is either :
    : : 1. Define our own menu [refer to below's link which teaches us to do
    : : OwnerDrawMenu
    : :
    : : http://www.codeguru.com/Cpp/controls/menu/article.php/c3721/
    : :
    : : 2. Change the window's settings [This is not really a good approach
    : : because it will force all other application to have the same colour]
    : :
    : :
    : : Is there anyone of you able to find other solution rather than these
    : : 2 i stated??
    : :
    : : Another question, if you tried to go for [1] solution, on that demo,
    : : it will only have the background change for menu items ONLY. For the
    : : right side of the MenuBar, the colour will keep on the default
    : : [which is gray]. Is there any ways to make the whole MenuBar[whole
    : : line] to have the colour that i preferred?
    : :
    : : Any help would be appreciated..
    : :
    : [color=Blue]
    : There is a way #3: completely new custom made menu bar. However, it
    : is a big implementation if you also need to do the popups. Just the
    : bar is not that bad. But, then you free to do anything you want -
    : any fancy stuff, gradients, etc.
    : [/color]



    What is the difference with #3 with #1 ?
    If I just want to do the MenuBar only.. without doing the popups menu, is it will be easier?
    Is there any link/tutorials which show me how to do it?
    Thanks for your reply

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    :
    : What is the difference with #3 with #1 ?
    : If I just want to do the MenuBar only.. without doing the popups
    : menu, is it will be easier?
    : Is there any link/tutorials which show me how to do it?
    : Thanks for your reply
    :
    :
    [color=Blue]The code sample in #1 uses the MF_OWNERDRAW style, which is a way of Windows to provide a hook into drawing menu items. #3 is a completely new class for menu bar with all drawing, including the background. If I have some spare time - I will post a sample of such solution (MFC).[/color]
  • karhongkarhong Member Posts: 14
    : :
    : : What is the difference with #3 with #1 ?
    : : If I just want to do the MenuBar only.. without doing the popups
    : : menu, is it will be easier?
    : : Is there any link/tutorials which show me how to do it?
    : : Thanks for your reply
    : :
    : :
    : [color=Blue]The code sample in #1 uses the MF_OWNERDRAW style, which
    : is a way of Windows to provide a hook into drawing menu items. #3 is
    : a completely new class for menu bar with all drawing, including the
    : background. If I have some spare time - I will post a sample of such
    : solution (MFC).[/color]


    I'll be trying to find example to draw a completely new class.
    But I'll be waiting for your sample, if you have spare time, then can you kindly get me a very very simple sample, with 1 menuitem, with the colour change for the whole MenuBar.
    Thanks in advance

    Best Regards
    KH

  • karhongkarhong Member Posts: 14
    To change the background color of MenuBar, simply add below's line of code, beginning of mainframe OnCreate

    CBrush* NewBrush;
    NewBrush = new CBrush;
    NewBrush->CreateSolidBrush(RGB(139,137,137));

    MENUINFO MenuInfo = {0};
    MenuInfo.cbSize = sizeof(MenuInfo);
    MenuInfo.hbrBack = *NewBrush; // Brush you want to draw
    MenuInfo.fMask = MIM_BACKGROUND;
    MenuInfo.dwStyle = MNS_AUTODISMISS;

    CMenu* pMenu = this->GetMenu();

    if(IsMenu(pMenu->m_hMenu))
    {
    SetMenuInfo(pMenu->m_hMenu, &MenuInfo);
    }

    As for Toolbar's background color, create OnNotify at MainFrame, put below's code

    LPNMHDR pnmh = (LPNMHDR) lParam;
    if(pnmh->hwndFrom == m_wndToolBar.m_hWnd)
    {
    LPNMTBCUSTOMDRAW lpNMCustomDraw = (LPNMTBCUSTOMDRAW) lParam;
    CRect rect;
    m_wndToolBar.GetClientRect(rect);
    FillRect(lpNMCustomDraw->nmcd.hdc, rect, (HBRUSH)GetStockObject(GRAY_BRUSH));

    }
    return CFrameWnd::OnNotify(wParam, lParam, pResult);



    Thanks for those who helped me. I'm giving out the solution i've got.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : To change the background color of MenuBar, simply add below's line
    : of code, beginning of mainframe OnCreate
    :
    : CBrush* NewBrush;
    : NewBrush = new CBrush;
    : NewBrush->CreateSolidBrush(RGB(139,137,137));
    :
    : MENUINFO MenuInfo = {0};
    : MenuInfo.cbSize = sizeof(MenuInfo);
    : MenuInfo.hbrBack = *NewBrush; // Brush you want to draw
    : MenuInfo.fMask = MIM_BACKGROUND;
    : MenuInfo.dwStyle = MNS_AUTODISMISS;
    :
    : CMenu* pMenu = this->GetMenu();
    :
    : if(IsMenu(pMenu->m_hMenu))
    : {
    : SetMenuInfo(pMenu->m_hMenu, &MenuInfo);
    : }
    :
    : As for Toolbar's background color, create OnNotify at MainFrame, put
    : below's code
    :
    : LPNMHDR pnmh = (LPNMHDR) lParam;
    : if(pnmh->hwndFrom == m_wndToolBar.m_hWnd)
    : {
    : LPNMTBCUSTOMDRAW lpNMCustomDraw = (LPNMTBCUSTOMDRAW) lParam;
    : CRect rect;
    : m_wndToolBar.GetClientRect(rect);
    : FillRect(lpNMCustomDraw->nmcd.hdc, rect,
    : (HBRUSH)GetStockObject(GRAY_BRUSH));
    :
    : }
    : return CFrameWnd::OnNotify(wParam, lParam, pResult);
    :
    :
    :
    : Thanks for those who helped me. I'm giving out the solution i've got.
    :
    [color=Blue]Nice solution. I forgot about CUSTOMDRAW message![/color]
  • psyafterpsyafter Member Posts: 1
    Hi

    how are you changed backcolor of toolbar placeholder?
    with event OnNotify it change just tolbar backcolor and not full placeholder of CMainFrame

    thanks
  • karhongkarhong Member Posts: 14
    oh hi..
    sorry for my SUPERB late reply

    OnCreate at CMainFrame
    Disable this 3 line

    m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);

    then it should be working.
  • mahaommahaom Member Posts: 1
    When I just declare the variable

    MENUINFO MenuInfo = {0};

    the compiler says:

    error C2065: 'MENUINFO' : undeclared identifier

    i've included windows.h.
    Any Ideas?
Sign In or Register to comment.