如何在.NET中调用DrawThemeTextEx
我需要在 Vista/7 玻璃窗中编写带有发光效果的文本,并且我正在尝试调用 API 来在那里编写一些文本。我在 CodeProject 中查看了一个很棒的 示例,但问题是我我正在使用 .NET 1(请不要问:-)
我需要将以下 .NET 2 代码转换为 PInvoke、.NET 1 代码。
// using System.Windows.Forms.VisualStyles
VisualStyleRenderer renderer = new VisualStyleRenderer(
VisualStyleElement.Window.Caption.Active);
// call to UxTheme.dll
DrawThemeTextEx(renderer.Handle,
memoryHdc, 0, 0, text, -1, (int)flags,
ref textBounds, ref dttOpts);
.NET 1 中不存在 VisualStyleRenderer 类,因此我需要以其他方式获取 renderer.Handle 。
I need to write a text with glow in a Vista/seven glass window, and I'm, trying to call the API to write some text there. I have checked out a great sample in CodeProject, but the problem is that I'm using .NET 1 (please, don't ask :-)
I need to translate the following .NET 2 code to PInvoke, .NET 1 code.
// using System.Windows.Forms.VisualStyles
VisualStyleRenderer renderer = new VisualStyleRenderer(
VisualStyleElement.Window.Caption.Active);
// call to UxTheme.dll
DrawThemeTextEx(renderer.Handle,
memoryHdc, 0, 0, text, -1, (int)flags,
ref textBounds, ref dttOpts);
The class VisualStyleRenderer
does not exist in .NET 1, so I need to get the renderer.Handle
in other way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义 OpenThemeData API 和 DrawThemeTextEx,以及一些必需的结构和常量:
然后,像这样调用它:
WS_CAPTION 和 CS_ACTIVE 值分别与 .NET 2 的 Caption 和 Active 匹配。此处正式描述了值:部件和状态
Define the OpenThemeData API and DrawThemeTextEx, as well as some required structs and constants:
And then, call it like this:
The WS_CAPTION and CS_ACTIVE values match .NET 2's Caption and Active respectively. Values are described here officially: Parts and States
简而言之,您可以通过调用 <代码>OpenThemeData()。
要弄清楚所有细节,您可以更轻松地用 C++ 编写示例应用程序来了解如何从头开始驱动主题 API。网上有很多教程和大量示例代码。但是在 C++ 中进行,您将可以轻松使用所有功能。您最不想做的事情就是与 P/Invokes 作斗争,同时您还要掌握低级主题 API。
一旦你用 C++ 破解了它,然后继续使用 P/Invokes,如果遇到问题,可以很容易地返回到有效的 C++ 代码。
In short, you get what you want by calling
OpenThemeData()
.To work out all the details it would be much easier for you to write a sample app in C++ to get to know how to drive the theme API from the ground up. There are many tutorials and lots of sample code on the web. But do it in C++ where you will have all the functions readily available. The last thing you want to get doing is fighting with P/Invokes whilst you are also getting to grips with low-level theme API.
Once you get it cracked in C++, then move on to the P/Invokes and if you have trouble it will be easy to refer back to the C++ code that works.