views:

646

answers:

3

Is there a way to change the colors used by plain Win32 menus (background, text, and highlight) for a single process, without using SetSysColors?

(SetSysColors does a global change, which is bad, and if you crash or forget to set the colors back with SetSysColors again before exiting, they will not be restored until you logout.)

+1  A: 

The SetMenuInfo() API is your friend. It lets you apply any brush to paint your menu's background.

Something along these lines should solve your problem:

MENUINFO mi = { 0 }; 
mi.cbSize = sizeof(mi); 
mi.fMask = MIM_BACKGROUND|MIM_APPLYTOSUBMENUS; 
mi.hbrBack = hBrush; 

HMENU hMenu = ::GetMenu(hWnd); 
SetMenuInfo(hMenu, &mi);
Serge - appTranslator
Unfortunately, that only solves part of the problem. Setting the background color without setting the foreground colors is a bad idea if the user has changed the foreground colors from the default, or if you do want to change the foreground colors.
CesarB
Right. For some reason, my brain skipped the text and highlight requests of the OP :-(
Serge - appTranslator
A: 

I have to ask, why? Adopting the regular Windows look-and-feel is good; it means users can be confident that there are consistent elements in your user interface, onto which they can map their experience using other software for the platform.

[I'm probably preaching to the converted, of course, but I thought I'd make the point so anyone who reads an answer for this doesn't start making all their menus sky-blue-pink 'cause it looks pretty.]

Rob
For consistency with the rest of the program's interface, which already does not follow the regular Windows look-and-feel. It was already this way when I started working there, and I want to make it stop using SetSysColors. For that, I need an alternative.
CesarB
Nearly everything coming out of Redmond draws their menus differently then plain Win32 menus. It really annoys me that this never makes into the OS. OS-level Windows menus are so far out of date that drawing them yourself is nearly a requirement these days.
Aardvark
+1  A: 

If I believe your comment to Rob, it is for a skinned application, with special look and feel. So the way to go is probably indeed, as ferek points out (in an unfriendly way...) to use owner-drawn menus: you will be able to define precisely their look.

PhiLho