Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Win32 menu colors

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.)

like image 774
CesarB Avatar asked Dec 02 '22 09:12

CesarB


2 Answers

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); 
like image 67
Serge Wautier Avatar answered Dec 23 '22 13:12

Serge Wautier


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.

like image 25
PhiLho Avatar answered Dec 23 '22 15:12

PhiLho