将自定义视觉样式 (.msstyle) 应用到单个 Winforms 应用程序

发布于 2024-10-28 19:12:54 字数 161 浏览 1 评论 0原文

有没有办法将自定义视觉样式 (.msstyle) 应用于 Windows 窗体应用程序而不更改整个系统的主题?基本上,我们希望我们的应用程序保持相同的主题,无论控制面板中设置了什么。请不要告诉我您是否认为这是一个好主意。我想知道是否有任何方法可以做到这一点而不涉及专有库,例如一系列本机 API 调用。谢谢!

Is there any way to apply a custom Visual Style (.msstyle) to a Windows Forms application without changing the theme of the entire system? Basically we want our application to maintain the same theme regardless of what has been set in Control Panel. Please don't tell me whether you think this is a good idea. I am wondering if there is any way to do this that doesn't involve a proprietary library, like a series of native API calls. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2024-11-04 19:12:54

SetWindowTheme函数看起来像是您正在寻找的解决方案。您必须执行 P/Invoke 才能使用它。

The SetWindowTheme function looks like the solution you 're looking for. You 'll have to do P/Invoke to use it.

草莓味的萝莉 2024-11-04 19:12:54

遗憾的是,这需要大量的挂钩,而不仅仅是简单的 P/Invoke。

使用托管代码覆盖/创建新控件可能会更快更好。否则,您需要在本机 DLL 的帮助下挂钩主题调用,并且在操作时要非常小心。

事实上,恐怕我自己也不知道如何具体实现。那么我会给出更有帮助的答案。通过查看 Style Soft(该公司似乎自 2014 年以来似乎已经死亡)现已废弃的工具“VisualStyler”的代码,整个过程似乎过于复杂,该工具很好地支持了所有这些。

另外,如果您真的决定使用 uxtheme,您将受制于 Windows 主题引擎提供的内容,仅限于其视觉样式文件格式和小问题(现在您是否有一个好的编辑器?)。

我希望微软在为 XP 创建主题引擎时能够认真思考,允许应用程序开发人员将其用于自己的应用程序标识。但当涉及到主题/Windows 产品标识时,他们似乎从来没有这样做(另一个例子是 DWM 没有公开任何 3D 转换功能,但这可能是一个好主意,可以防止应用程序通过滥用这些东西来做出疯狂的事情)。

选项?

  • 在托管代码中创建您自己的控件,自行处理绘图。
  • 购买适用于 Win32 应用程序的产品。
  • 开始了解 WPF,它提供了创建应用程序主题的现代且合理的方法。

This sadly requires a lot of hooking and not just simple P/Invoke.

You're probably faster and better off overriding / creating new controls with managed code. Otherwise you'll need to hook theming calls, with the help of a native DLL, and be very careful in what you do.

In fact, I don't know how to implement it myself exactly, I'm afraid. I would've given a more helpful answer then. The whole progress seems overly complicated by looking into the code of a now abandoned tool called "VisualStyler" by Style Soft (the company seems dead since 2014) which nicely supported all of this.

Plus if you really decide to use uxtheme, you'll be stuck with what the Windows theming engine provides, limited to its visual style file format and hickups (do you even have a good editor nowadays?).

I wish Microsoft would've done nails with heads when they created the theming engine for XP, allowing application developers to utilize it for their own application identity. But they never seem to do that when it comes to theming / Windows product identity (another example is DWM not exposing any 3D transformational features, but it's probably a good idea to prevent applications doing insane things by abusing such stuff).

Options?

  • Create your own controls in managed code, handling drawing by yourself.
  • Buy a product offering that for Win32 applications.
  • Start to get into WPF which provides modern and sane ways to create application themes.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文