如何使用GetThemeFont读取字体数据?
我正在尝试使用 GetThemeFont 从视觉样式读取字体数据,但我似乎无法让它返回任何内容。 这是我使用它的方式:
IntPtr h = OpenThemeData(this.Handle, "Button");
LOGFONT font = new LOGFONT();
int r = GetThemeFont(h, IntPtr.Zero, 1, 1, 210, out font);
CloseThemeData(h);
返回值始终为“-2147023728”,字体始终为空。 我放置 210(用于 TMT_FONT)的地方,我不太确定在那里使用什么。 对此的任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-2147023728 是 0x80070490L 的十进制等效值,它是分配给
E_PROP_ID_UNSUPPORTED
的值。 来自 GetThemeFont 文档的“备注”部分:您传入的部件和状态组合不支持该属性。
-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:The property is not supported for the part and state combination that you are passing in.
参阅此要点https://gist.github.com/1219126
请 null,或不支持的结果。 此外,如果您尝试在托管应用程序中使用 TMT_FONT (210),它会引发一个不错的内存错误并清除堆栈(谁知道什么原因)。
VisualStyleRenderer.GetFont 和/或 GetThemeFont 的内部本质上存在缺陷。 我正在尝试与 MS 的一些人合作解决这个问题,并提供解决方法、更多文档或承认此问题已被破坏。
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.