2

The Windows API has the DrawThemeText Function for drawing text to a rectangle in the style of a certain part and state according to the specified Windows theme. (Andreas Rejbrand made a neat application demonstrating parts and states.)

Is it possible to determine what font face, size and colour is used for a given part and state?

GetSystemMetrics can be used to find out about only some system fonts.

Community
  • 1
  • 1
Quppa
  • 1,841
  • 20
  • 18

2 Answers2

2

There's a bevy of GetThemeXxxx() functions. You're probably looking for, respectively, GetThemeFont(), GetThemeMetric() and GetThemeColor(). The metric one was a bit of a guess, there are several other sizing related ones. GetThemeFont also returns the font size. Start here in the MSDN library.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Wow, I'm not sure how I missed all those functions. Cheers. – Quppa Mar 08 '11 at 05:47
  • GetThemeFont() and GetThemeColor() are indeed the functions to use. The former will return the font face/size/weight/etc. (it returns a LOGFONT) and the latter will return the font colour given the TMT_TEXTCOLOR property. – Quppa Mar 08 '11 at 11:43
  • I ended up writing a bit about this here: http://blog.quppa.net/2011/04/30/windows-theme-fonts/ – Quppa Apr 30 '11 at 14:59
0

I've not been able to track down a single working example of GetThemeFont, let alone the managed version of VisualStyleRenderer.GetThemeFont. Examining the Mono source yields a comment by the author that they also could not get GetThemeFont to return anything but null.

Use of TMT_FONT consistently throws an unmanaged memory error and use of TMT_GLYPHFONT consistently returns the 'not supported' error. This particular api appears to be horribly flawed and (dare I say it) non-functional.

The reply marked as an answer isn't an answer at all. The author asked how to drive and you pointed him at a car that wouldn't start.

shellscape
  • 840
  • 1
  • 6
  • 17
  • I've added a test in the form of a gist to show that the managed wrapper for GetThemeFont, VisualStyleRenderer.GetFont, doesn't return a non-null value for any of the VisualStyleElements https://gist.github.com/1219126. If you examine the method using Reflector, you'll see how they handle GetThemeFont in a managed environment - not that it matters much. – shellscape Sep 15 '11 at 12:42
  • I've posted a WPF sample here: http://blog.quppa.net/2011/10/24/windows-theme-fonts-redux-sample-code/ – Quppa Oct 23 '11 at 16:21