MenuBar and ToolBar background color
-
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..
good
-
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..
good
You could try experimenting with WM_NCPAINT.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
You could try experimenting with WM_NCPAINT.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
Sorry, i tried to look into WM_NCPAINT. But i dont get any good link which help me on changing the menuBar and toolBar background color Is there any good link which u have? Thanks for your reply.
good
Well, sadly, no, i have no links, if i had one i would have posted it the first time, what i thought of is that you could try drawing the menubar yourself similarry to how you draw the menu items, it can be tricky but i think it can be done. Sorry, i have no better idea right now. If you could determine the menubar area you could in the call to WM_NCPAINT exclude this area from the update region (you get the update region as a parameter with WM_NCPAINT (i think it can also be NULL which means everything needs to be repainted)), call __super::OnNcPaint, this should leave the menubar area unpainted (but draw the rest, like borders, caption bar, ...) and then try to paint it yourself using GetMenuItemRect() to determine where the menu items are, however, this might prove problematic (i don't know how you can draw a menu item which is selected, etc...) and it is also probably reinventing the wheel...but you said you didn't find anything out there to do what you want. Or how about doing this: catch he WM_NCPAINT, determine the menu bar region, paint it to your chosen color, and then let WM_NCPAINT be handled by super, maybe it doesn't erase the menubar background in that call just draws the items over what is there. Maybe worth a try...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
Well, sadly, no, i have no links, if i had one i would have posted it the first time, what i thought of is that you could try drawing the menubar yourself similarry to how you draw the menu items, it can be tricky but i think it can be done. Sorry, i have no better idea right now. If you could determine the menubar area you could in the call to WM_NCPAINT exclude this area from the update region (you get the update region as a parameter with WM_NCPAINT (i think it can also be NULL which means everything needs to be repainted)), call __super::OnNcPaint, this should leave the menubar area unpainted (but draw the rest, like borders, caption bar, ...) and then try to paint it yourself using GetMenuItemRect() to determine where the menu items are, however, this might prove problematic (i don't know how you can draw a menu item which is selected, etc...) and it is also probably reinventing the wheel...but you said you didn't find anything out there to do what you want. Or how about doing this: catch he WM_NCPAINT, determine the menu bar region, paint it to your chosen color, and then let WM_NCPAINT be handled by super, maybe it doesn't erase the menubar background in that call just draws the items over what is there. Maybe worth a try...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
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.
good