0

I am trying to use GetThemeFont to read the font data from a visual style, but I can't seem to get it to return anything. Here is how I'm using it:

IntPtr h = OpenThemeData(this.Handle, "Button");
LOGFONT font = new LOGFONT();
int r = GetThemeFont(h, IntPtr.Zero, 1, 1, 210, out font);
CloseThemeData(h);

The return value is always "-2147023728" and font is always null. The place where I put 210 (for TMT_FONT), I'm not really sure what to use there. Any help on this would be much appreciated.

Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168

2 Answers2

1

-2147023728 is the decimal equivalent of 0x80070490L, which is the value assigned to E_PROP_ID_UNSUPPORTED. From the "Remarks" section of the documentation of of GetThemeFont:

If the property is not supported for the specified part and state, E_PROP_ID_UNSUPPORTED may be returned.

The property is not supported for the part and state combination that you are passing in.

casperOne
  • 73,706
  • 19
  • 184
  • 253
  • I have tried passing in every propId I can find, but I always get that error. I'm thinking that I'm doing something else wrong, but I'm not sure. – Jon Tackabury Jan 26 '09 at 14:12
1

See this gist https://gist.github.com/1219126

You'll never get back anything more than null, or the not supported result. Additionally, using TMT_FONT (210) will drop a nice memory error and clear the stack (for who knows what reason) if you attempt to use it within a managed app.

The internals of either VisualStyleRenderer.GetFont and/or GetThemeFont are inherently flawed. I'm trying to work with some people at MS to address this and provide either a workaround, more documentation or some acknowledgement that this is broken.

shellscape
  • 840
  • 1
  • 6
  • 17