Ele*_*ios 8 c# vb.net windows pinvoke winapi
在C#或VB.Net中,知道视觉主题.theme文件的使用,我想在Windows中应用该视觉主题,而不依赖于其他应用程序,如RunDll32.exe,只需P/Invoking,但避免怪异/奇怪的事情,如打开个性化窗口,然后使用FindWindow函数关闭它,程序应该从平台调用自动化,而不是与其他窗口交互.
关于如何应用主题的这个问题之前在很多人面前被问过(包括我,通过注册表修改加上服务停止/恢复只能在Windows 7下运行的解决方案),我认为是时候让专家来说明我们了使用不涉及RunDll32.exe的WinAPI方法既不打开个性化窗口.
我不知道这会通过在注册表项设置一些值来完成HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ThemeManager,然后发布/通过发送消息SendMessage或PostMessage或其它功能,或可能通知有关通过环境变化SendMessageTimeOut功能或SHChangeNotify或SystemParametersInfo或其他功能,因为在uxtheme.dll库中似乎有什么对于这个任务有用,问题是什么功能以及用什么参数来应用视觉主题变化,有一些商业应用程序可以做到这一点,那么这是做它的步骤?,我尝试了所有这些功能但没有成功.
这是我过去为Windows 7做的解决方案,我记得这并不完美,因为对于某些主题,颜色没有正确应用,只有用户会话重新登录才能解决,以便在修改后正确影响更改:
Private Sub SetAeroTheme(ByVal themeFile As String,
Optional ByVal colorName As String = "NormalColor",
Optional ByVal sizeName As String = "NormalSize")
Dim regKeyPath As String = "Software\Microsoft\Windows\CurrentVersion\ThemeManager"
Using themeService As New ServiceController("Themes")
If themeService.Status = ServiceControllerStatus.Running Then
themeService.Stop()
themeService.WaitForStatus(ServiceControllerStatus.Stopped)
End If
Using regKey As RegistryKey = Registry.CurrentUser.OpenSubKey(regKeyPath, writable:=True)
regKey.SetValue("LoadedBefore", "0", RegistryValueKind.String)
regKey.SetValue("DllName", themeFile, RegistryValueKind.String)
regKey.SetValue("ColorName", colorName, RegistryValueKind.String)
regKey.SetValue("SizeName", sizeName, RegistryValueKind.String)
End Using
If themeService.Status = ServiceControllerStatus.Stopped Then
themeService.Start()
themeService.WaitForStatus(ServiceControllerStatus.Running)
End If
End Using
End Sub
Run Code Online (Sandbox Code Playgroud)
在Windows 8中,我认为因为DWM组合只会改变代码不再起作用.
pinvoke.net上描述了一个名为“SetSystemVisualStyle”的未记录函数,它允许您更改当前的“msstyles”文件。由于此功能未记录在案,因此需要注意:“使用风险自负”。
以下函数签名来自上面引用的站点。
[DllImport("UxTheme.Dll", EntryPoint = "#65", CharSet = CharSet.Unicode)]
public static extern int SetSystemVisualStyle(string pszFilename, string pszColor, string pszSize, int dwReserved);
Run Code Online (Sandbox Code Playgroud)
用法:
// This will set your Visual Style to Luna
SetSystemVisualStyle(@"C:\WINDOWS\resources\Themes\Luna\Luna.msstyles", "Metallic", "NormalSize", 0);
Run Code Online (Sandbox Code Playgroud)
<DllImport("UxTheme.DLL", BestFitMapping:=False, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="#65")> _
Shared Function SetSystemVisualStyle(ByVal pszFilename As String, ByVal pszColor As String, ByVal pszSize As String, ByVal dwReserved As Integer) As Integer
End Function
Run Code Online (Sandbox Code Playgroud)
OP 要求将以下信息添加到此答案中。
当使用自定义 msstyles 应用 3rd 方主题时,该函数本身不会正确更改某些对话框颜色和某些控件样式,而是通过测试从 0 到 Int32.Max 的所有可能值将其传递给保留参数SetSystemVisualTheme 函数,当我发现 65 的值修复了这个着色和样式问题时。
| 归档时间: |
|
| 查看次数: |
903 次 |
| 最近记录: |