Reputation: 49289
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.
Upvotes: 0
Views: 647
Reputation: 885
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.
Upvotes: 1
Reputation: 74560
-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.
Upvotes: 1