我在 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.
发布评论
评论(3)
就我个人而言,我使用以下命令来查看应用程序是否在主题下运行:
Personally, I use the following to see if the app is running under themed:
有 IsThemeActive WinAPI 函数。
There's the IsThemeActive WinAPI function.
尝试使用 GetCurrentThemeName (MSDN 页面) 和 DwmIsCompositionEnabled
我将第一个链接到 PInvoke,以便您可以将其放入代码中,然后第二个你可以使用 MSDN 评论中提供的代码:
看看你从这两个函数中得到了什么结果; 它们应该足以确定您何时想要使用不同的主题!
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:
See what results you get out of those two functions; they should be enough to determine when you want to use a different theme!