GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Dec-2008, 04:24
karhong karhong is offline
New Member
 
Join Date: Oct 2006
Posts: 11
karhong is on a distinguished road

Change MenuBar & 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..
  #2  
Old 05-Dec-2008, 11:33
george135 george135 is offline
Account Disabled
 
Join Date: Jan 2008
Posts: 25
george135 has a little shameless behaviour in the past

Re: Change MenuBar & ToolBar background color


You don't need owner-draw,
you can do anything with Win32 api
(You can ask on specialized Win32 api newsgroup :
comp.os.ms-windows.programmer.win32 )
where it has been discussed
  #3  
Old 09-Dec-2008, 03:17
karhong karhong is offline
New Member
 
Join Date: Oct 2006
Posts: 11
karhong is on a distinguished road
Thumbs up

Re: Change MenuBar & ToolBar background color


To change the background color of MenuBar, simply add the lines of code below, beginning of mainframe OnCreate

CPP / C++ / C Code:
        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.
Last edited by admin : 09-Dec-2008 at 03:47. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
triangle (polygon), drawing, sizing, and rotation programme using linked lists... promsan C Programming Language 12 14-May-2007 15:03
Change text color in C IndioDoido C Programming Language 2 15-Apr-2007 22:58
How do I change the background color of an entire edit control box, not just the... steph MS Visual C++ / MFC Forum 7 02-Jun-2006 10:15
change dlg background inbal79 MS Visual C++ / MFC Forum 3 19-Mar-2006 07:49
Multi-client application using sockets shereen Java Forum 0 03-Mar-2006 10:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:47.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.