纯代码启用 XP 样式 (不用额外的资源或 manifest 文件)
2009-11-21 13:23
351 查看
纯代码启用 XP 样式 (不用额外的资源或 manifest 文件)
manifest, 资源, 样式, 文件, 代码
将以下代码存为模块, 然后在第一个窗口的 Form_Initialize 事件或之前调用 EnableXPStyle 函数即可.
函数返回值为 True 表示成功, 注意必须编译后才有效果.
Option Explicit
Private Type ACTCTX
cbSize As Long
dwFlags As Long
lpSource As String
wProcessorArchitecture As Integer
wLangId As Integer
lpAssemblyDirectory As String
lpResourceName As String
lpApplicationName As String
hModule As Long
End Type
Private Declare Function GetWindowsDirectoryW Lib "kernel32.dll" (ByVal lpBuffer As Long, ByVal uSize As Long) As Long
Private Declare Function CreateActCtxW Lib "kernel32.dll" (ByVal pActCtx As Long) As Long
Private Declare Function ActivateActCtx Lib "kernel32.dll" (ByVal hActCtx As Long, ByRef lpCookie As Long) As Long
Dim IDEMode As Boolean
Private Function SetIDE() As Boolean
IDEMode = True
SetIDE = True
End Function
Public Function EnableXPStyle() As Boolean
Dim Length As Long, Path As String, Ctx As ACTCTX, hActCtx As Long, Cookie As Long
Debug.Assert SetIDE
If IDEMode = False Then
Length = GetWindowsDirectoryW(0, 0)
If Length <> 0 Then
Path = Space(Length - 1)
If GetWindowsDirectoryW(StrPtr(Path), Length) <> 0 Then
Ctx.cbSize = Len(Ctx)
Ctx.lpSource = Path & "/WindowsShell.manifest"
hActCtx = CreateActCtxW(VarPtr(Ctx))
If hActCtx <> -1 Then
If ActivateActCtx(hActCtx, Cookie) <> 0 Then
EnableXPStyle = True
End If
End If
End If
End If
End If
End Function
manifest, 资源, 样式, 文件, 代码
将以下代码存为模块, 然后在第一个窗口的 Form_Initialize 事件或之前调用 EnableXPStyle 函数即可.
函数返回值为 True 表示成功, 注意必须编译后才有效果.
Option Explicit
Private Type ACTCTX
cbSize As Long
dwFlags As Long
lpSource As String
wProcessorArchitecture As Integer
wLangId As Integer
lpAssemblyDirectory As String
lpResourceName As String
lpApplicationName As String
hModule As Long
End Type
Private Declare Function GetWindowsDirectoryW Lib "kernel32.dll" (ByVal lpBuffer As Long, ByVal uSize As Long) As Long
Private Declare Function CreateActCtxW Lib "kernel32.dll" (ByVal pActCtx As Long) As Long
Private Declare Function ActivateActCtx Lib "kernel32.dll" (ByVal hActCtx As Long, ByRef lpCookie As Long) As Long
Dim IDEMode As Boolean
Private Function SetIDE() As Boolean
IDEMode = True
SetIDE = True
End Function
Public Function EnableXPStyle() As Boolean
Dim Length As Long, Path As String, Ctx As ACTCTX, hActCtx As Long, Cookie As Long
Debug.Assert SetIDE
If IDEMode = False Then
Length = GetWindowsDirectoryW(0, 0)
If Length <> 0 Then
Path = Space(Length - 1)
If GetWindowsDirectoryW(StrPtr(Path), Length) <> 0 Then
Ctx.cbSize = Len(Ctx)
Ctx.lpSource = Path & "/WindowsShell.manifest"
hActCtx = CreateActCtxW(VarPtr(Ctx))
If hActCtx <> -1 Then
If ActivateActCtx(hActCtx, Cookie) <> 0 Then
EnableXPStyle = True
End If
End If
End If
End If
End If
End Function
相关文章推荐
- Style样式的四种使用(包括用C#代码动态加载资源文件并设置样式)
- 将XP风格文件manifest合并到资源文件
- 将XP风格文件manifest合并到资源文件
- 在资源文件添加代码的详细方法和步骤
- 资源文件格式转换工具(.html)代码
- Android APK代码混淆和资源文件混淆
- type=file导入文件按钮样式修改的jsp代码-完美好
- 不用浏览器,直接用代码发送文件给webservices所在服务器 并且可以周期行的发送
- Android 常用代码---资源文件
- JS判断不同分辨率调用不同的CSS样式文件实现思路及测试代码
- WPF样式资源文件简单运用
- XP 远程桌面连接不能复制文件 - 设置本地资源
- 如何不用额外工具查找Windows7系统中的大文件
- 在c#中代码模糊与资源文件
- Myeclipse2015 Jrebel插件的安装、配置、使用(新建.java文件、给类添加新方法、新属性、修改代码等,不用重启tomcat即可更新)
- 组件用户控件引用样式资源(二)---代码引用
- [VB.NET]vb.net启用xp样式问题?
- (实用篇)PHP不用递归遍历目录下所有文件的代码
- VS编辑代码的时候,都会自动在资源浏览器里将文件所在项目展开
- 如何反编译Android的Apk文件获取其代码和资源文件