Search code examples
c#winapimsstyles

How do I use GetThemeFont to read font data?


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.


Solution

  • -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.