VB编程实现XP风格之终结篇[组图](2)
假设你最终编译的程序名是abc.exe,工作目录是d:vbxp。复制上述XML内容并保存为文本文件。然后将该文件改名为abc.exe.manifest(注意.txt扩展名要去掉)。在VB程序中,我们要在所有窗体加载之前调用InitCommonControlsEx函数从comctl32.dll(版本6)中对组件类进行初始化。API函数InitCommonControlsEx及相关常数、数据类型的声明如下:
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" _
(iccex As tagInitCommonControlsEx) As Boolean
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Const ICC_USEREX_CLASSES = &H200
这里我们编写一个函数封装初始化操作:
Public Function InitCommonControlsVB() As Boolean
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error Goto 0
End Function
注意初始化动作必须在所有窗体加载前完成,所以要把相关语句放到Sub Main()中,并设置工程从Sub Main()启动。代码如下:
Sub Main()
InitCommonControlsVB
Form1.Show
End Sub
至此,你编译后的abc.exe将具备XP风格,如图2所示: