1

I am emulating (to the degree possible) a TPopup Menu so it can float and users can drag it around.

To do this, it's on its own form, and uses TPanels acting as if they are clickable TMenuItems.

I'm using TPanels so I can change their color.

To get the colors right, how can I determine at runtime (in Delphi 2010) the current theme's colors for TMenuItem.Color and TMenuItem.Font.Color (assuming such properties existed).

TIA

Edit

I could use clBtnFace for the background, and clWindowText for the text color. But, I need to know the the theme colors for when the mouse is over a menu selection.

RobertFrank
  • 7,332
  • 11
  • 53
  • 99

3 Answers3

5

Have a look at my answer to How can I get the color for a themed tabsheet - especially the edit.

The relevant constants can be found under Parts and States. Just search for "MENU" on that page.

Edit: There are tools to explore themes visually - see Windows Visual Themes: Gallery of Parts and States?. (Thanks to @TOndrej for bringing this up.)

Community
  • 1
  • 1
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
  • 4
    +1, and [here](http://stackoverflow.com/questions/4009701/windows-visual-themes-gallery-of-parts-and-states/4009712#4009712) is [Andreas Rejbrand](http://stackoverflow.com/users/282848/andreas-rejbrand)'s UxExplore tool which allows you to explore themes and their elements. – Ondrej Kelle May 30 '11 at 16:15
4

I believe the popupmenu uses the colour in the clMenu constant. If you need the colour as an rgb value, use ColorToRgb(clMenu) to translate it. There's clMenuBar, clMenuText and clMenuHighlight constants too.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • 3
    As long as themes are defined using "Parts", a single color will never cut it, not even if today's Themes happen to only use a single color. The "parts" might be changed by third party theming software or by future versions of Windows. `clMenu` is not the "themed color", it's the menu color when NOT themed. Using true theming is not that difficult. – Cosmin Prund May 31 '11 at 08:30
  • Hi, Cosmin. Can you give me a brief overview of how to use true theming to emulate the TMainMenu appearance (text and background)? Thanks! – RobertFrank May 31 '11 at 14:01
1

You can use the constants clMenu and clMenuText.

There are more windows colors defined in Graphics.pas

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202