简体   繁体   中英

C++ how can I set color in menu items?

I'm beggining Windows API programming recently. I'm curious about how to set menu bar a color and items as well. I tried to search it on google but couldn't find it.

I've created window using CreateWindowEx() , and created menu using CreateMenu() .

Since you are into beginning phase of Win32 development, I highly suggest you to stay away from colouring the menus. They are not natively supported by Win32 library. You need to do custom drawing for such colourful menus. You may search for "custom draw menus in win32" (replace win32 with MFC, if you can work with MFC).

But the search results will baffle you, and you'd not be able to grasp it. I suggest you to play with windows, menus, controls, processing of various windows and user initiated messages. Work on enabling/disabling controls, hiding controls, changing the properties of controls. What about making something like Windows Explorer (right side only)? You'll learn a lot. There is absolutely no need to jump into jazzy world of colours (at least for menus).

If you want to have colours, gradients etc. you can do that on windows itself ( HDC , WM_PAINT , etc).

You cannot style too much default UI primitives on Windows. They are drawn by system.

But you may have so called owner drawn menu items where you can draw anything you want.

If your design requires a lot of custom drawn elements then you probably shall consider other approaches for your UI. Like QT/QML or my Sciter for example where you can define menus in HTML/CSS terms:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM