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

时间:2020-03-05 18:45:04  来源:igfitidea点击:

我在VB 2005中有一些UI,在XP Style中看起来很棒,但是在Classic Style中却很丑陋。

关于如何检测用户处于哪种模式并即时重新设置表格格式的任何想法?

发表答案编辑:

谢谢丹尼尔,看起来这行得通。我正在使用通过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

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.

Solution

Answer

There's the IsThemeActive WinAPI function.

Answer

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();

代码数量不匹配