第一个form_initialize或者sub main的时候用initcommoncontrols
Private Declare Sub InitCommonControls Lib "COMCTL32" ()
然后给这个程序写个manifest文件
保存在同一个文件夹
例如工程1.exe
就保存为工程1.exe.manifest
manifest文件内容如下
processorArchitecture="X86"
name="YOURNAME"
type="win32"
/>
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
用记事本保存就行啦
当然,也可以在exe里面注入manifest资源
代码如下
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1'Fixed Single
Caption = "MANIFEST INJECTOR"
ClientHeight= 3690
ClientLeft= 45
ClientTop = 435
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3690
ScaleWidth= 4680
StartUpPosition = 3'窗口缺省
Begin VB.TextBox Text3
Height= 270
Left= 480
TabIndex= 3
Top = 2520
Width = 3615
End
Begin VB.TextBox Text2
Height= 270
Left= 480
TabIndex= 2
Text= "FileName"
Top = 2880
Width = 3855
End
Begin VB.CommandButton Command1
Caption = "Inject"
Height= 375
Left= 960
TabIndex= 1
Top = 3240
Width = 1815
End
Begin VB.TextBox Text1
Height= 2295
Left= 720
MultiLine = -1'True
ScrollBars= 2'Vertical
TabIndex= 0
Text= "Form1.frx":0000
Top = 120
Width = 3615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, lpType As Long, lpName As Long, ByVal wLanguage As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function FindResource Lib "kernel32" Alias "FindResourceA" (ByVal hInstance As Long, ByVal lpName As String, ByVal lpType As String) As Long
Private Declare Function LoadResource Lib "kernel32" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function LockResource Lib "kernel32" (ByVal hResData As Long) As Long
Private Declare Function SizeofResource Lib "kernel32" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Const LANG_ENGLISH = &H9
Private Declare Sub InitCommonControls Lib "COMCTL32" ()
Private Function uResM(FName$, stU$)
Dim rHandle As Long, maniStr As String
rHandle = BeginUpdateResource(FName, False)
maniStr = stU
uResM = UpdateResource(rHandle, ByVal 24, ByVal 1, ByVal 0, ByVal maniStr, Len(maniStr))
EndUpdateResource rHandle, 0
End Function
Private Sub Command1_Click()
Dim rHandle As Long, manifestByteArray() As Byte, maniStr As String
If MsgBox("Create Backup?", vbYesNo, "Manifest Injector") = vbYes Then Call FileCopy(Text2.Text, Text2.Text & "_original.bak")
If uResM(Text2.Text, Text1.Text) Then MsgBox "Done", vbInformation, "Manifest Injector"
End Sub
Private Sub Form_Initialize()
InitCommonControls
End Sub
Private Sub Form_Load()
If Command <> "" Then
On Error Resume Next
Dim cmd$, st$, leftPars As String, ps$()
Dim SMode As Boolean
Dim Backup As Boolean
SMode = False
Backup = True
cmd = Command
Dim iSt As Long
Dim iEnd As Long
iSt = InStr(1, cmd, Chr(34))
iEnd = InStr(iSt + 1, cmd, Chr(34))
If iSt > 0 And iEnd > 0 Then
st = Mid(cmd, iSt + 1, iEnd - iSt - 1)
If iSt > 1 Then leftPars = Trim(Mid(cmd, iEnd + 1, Len(cmd) - iEnd)): leftPars = leftPars & " " & Trim(Mid(cmd, 1, iSt - 1)) Else leftPars = Trim(Mid(cmd, iEnd + 1, Len(cmd) - iEnd))
ElseIf iSt > 0 And iEnd = 0 Then
MsgBox "Parameter Error.", vbCritical, "Error"
Exit Sub
ElseIf iSt = 0 And iEnd = 0 Then
st = Mid(cmd, 1, InStr(1, cmd, " ") - 1)
If st = "" Then st = Mid(cmd, 1, InStr(1, cmd, "/") - 1)
If st = "" Then st = cmd
leftPars = Trim(Mid(cmd, InStr(1, cmd, " "), Len(cmd) - InStr(1, cmd, " ") + 1))
End If
ps = Split(leftPars, "/")
Dim i&
For i = 0 To UBound(ps)
Select Case Trim(UCase(ps(i)))
Case "S"
SMode = True
Case "B"
Backup = True
Case "NB"
Backup = False
End Select
Next i
If Backup = True Then Call FileCopy(st, st & "_original.bak")
If uResM(st, Text1.Text) And SMode = False Then
MsgBox "UpdateResource successfully.", vbInformation, "Manifest Injector"
ElseIf SMode = False Then
MsgBox Chr(34) & st & Chr(34) & " UpdateResource failed.", vbInformation, "Manifest Injector"
End If
End
End If
End Sub
保存为一个form就能用啦。。
如果你是用默认button控件的话,不需要任何设置
对的,你试一下不就知道了
做不到。