.Net - 检测外观设置(经典还是 XP?)

发布于 2024-07-04 03:12:28 字数 1114 浏览 7 评论 0 原文

我在 VB 2005 中有一些 UI,在 XP 风格中看起来很棒,但在经典风格中却很丑陋。

关于如何检测用户所处的模式并动态重新格式化表单的任何想法?


发布答案编辑:

谢谢丹尼尔,看起来这会起作用。 我正在使用您通过 GetCurrentThemeName() 函数发布的第一个解决方案。

我正在执行以下操作:

函数声明:

 Private Declare Unicode Function GetCurrentThemeName Lib "uxtheme" (ByVal stringThemeName As System.Text.StringBuilder, ByVal lengthThemeName As Integer, ByVal stringColorName As System.Text.StringBuilder, ByVal lengthColorName As Integer, ByVal stringSizeName As System.Text.StringBuilder, ByVal lengthSizeName As Integer) As Int32

代码正文:


Dim stringThemeName As New System.Text.StringBuilder(260)
Dim stringColorName As New System.Text.StringBuilder(260)
Dim stringSizeName As New System.Text.StringBuilder(260)

获取当前主题名称(字符串主题名称,260,字符串颜色名称,260,字符串大小名称,260) MsgBox(字符串主题名称.ToString)

当我使用 Windows 经典样式/主题时,消息框显示为空,如果使用 Windows XP 样式/主题,则显示“C:\WINDOWS\resources\Themes\luna\luna.msstyles”。 我必须做更多检查,看看如果用户设置除这两个主题之外的另一个主题会发生什么,但这应该不是一个大问题。

I have some UI in VB 2005 that looks great in XP Style, but goes hideous in Classic Style.

Any ideas about how to detect which mode the user is in and re-format the forms on the fly?


Post Answer Edit:

Thanks Daniel, looks like this will work. I'm using the first solution you posted with the GetCurrentThemeName() function.

I'm doing the following:

Function Declaration:

 Private Declare Unicode Function GetCurrentThemeName Lib "uxtheme" (ByVal stringThemeName As System.Text.StringBuilder, ByVal lengthThemeName As Integer, ByVal stringColorName As System.Text.StringBuilder, ByVal lengthColorName As Integer, ByVal stringSizeName As System.Text.StringBuilder, ByVal lengthSizeName As Integer) As Int32

Code Body:


Dim stringThemeName As New System.Text.StringBuilder(260)
Dim stringColorName As New System.Text.StringBuilder(260)
Dim stringSizeName As New System.Text.StringBuilder(260)

GetCurrentThemeName(stringThemeName, 260, stringColorName, 260, stringSizeName, 260) MsgBox(stringThemeName.ToString)

The MessageBox comes up Empty when i'm in Windows Classic Style/theme, and Comes up with "C:\WINDOWS\resources\Themes\luna\luna.msstyles" if it's in Windows XP style/theme. I'll have to do a little more checking to see what happens if the user sets another theme than these two, but shouldn't be a big issue.

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

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

发布评论

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

评论(3

携君以终年 2024-07-11 03:12:28

就我个人而言,我使用以下命令来查看应用程序是否在主题下运行:

if (Application.RenderWithVisualStyles)
{
    // you're themed
}

Personally, I use the following to see if the app is running under themed:

if (Application.RenderWithVisualStyles)
{
    // you're themed
}
又爬满兰若 2024-07-11 03:12:28

IsThemeActive WinAPI 函数。

There's the IsThemeActive WinAPI function.

清风疏影 2024-07-11 03:12:28

尝试使用 GetCurrentThemeName (MSDN 页面) 和 DwmIsCompositionEnabled

我将第一个链接到 PInvoke,以便您可以将其放入代码中,然后第二个你可以使用 MSDN 评论中提供的代码:

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

看看你从这两个函数中得到了什么结果; 它们应该足以确定您何时想要使用不同的主题!

Try using a combination of GetCurrentThemeName (MSDN Page) and DwmIsCompositionEnabled

I linked the first to PInvoke so you can just drop it in your code, and for the second one you can use the code provided in the MSDN comment:

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

See what results you get out of those two functions; they should be enough to determine when you want to use a different theme!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文