RegisterUserApiHook函数的VB声明如下:
Public Declare Function RegisterUserApiHookXP Lib "user32" Alias "RegisterUserApiHook" (ByVal hInstance As Long, ByVal fnUserApis As Long) As Long
Public Declare Function RegisterUserApiHook2003 Lib "user32" Alias "RegisterUserApiHook" (pRegInfo As HookAPIRegInfo2003) As Long
LpkHooksInfo.lpHookProc_LpkTabbedTextOut = 0
LpkHooksInfo.lpHookProc_LpkPSMTextOut = 0
LpkHooksInfo.lpHookProc_LpkDrawTextEx = GetLocalProcAdress(AddressOf HookProc1) '设置要HOOK的LPK函数
LpkHooksInfo.lpHookProc_LpkEditControl = 0
InitializeLpkHooks LpkHooksInfo
End Sub
Private Sub Form_Unload(Cancel As Integer)
LpkHooksInfo.lpHookProc_LpkTabbedTextOut = 0
LpkHooksInfo.lpHookProc_LpkPSMTextOut = 0
LpkHooksInfo.lpHookProc_LpkDrawTextEx = DLLFunDre
LpkHooksInfo.lpHookProc_LpkEditControl = 0
InitializeLpkHooks LpkHooksInfo
FreeLibrary DLLhwnd
End Sub
然后新建一个模块,在模块中加入以下代码:
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
' ----------------未公开函数--------------------------------------
Public Declare Sub InitializeLpkHooks Lib "user32" (lpProcType As Any)
Type LpkHooksSetting
lpHookProc_LpkTabbedTextOut As Long
lpHookProc_LpkPSMTextOut As Long
lpHookProc_LpkDrawTextEx As Long
lpHookProc_LpkEditControl As Long
End Type
' -------------------------------
Public DLLhwnd As Long, DLLFunDre As Long
Public LpkHooksInfo As LpkHooksSetting
Public Function GetLocalProcAdress(ByVal lpProc As Long) As Long
GetLocalProcAdress = lpProc
End Function
Function HookProc1(ByVal a1 As Long, ByVal a2 As Long, ByVal a3 As Long, ByVal a4 As Long, ByVal a5 As Long, ByVal a6 As Long, ByVal a7 As Long, ByVal a8 As Long, ByVal a9 As Long, ByVal a10 As Long) As Long
HookProc1 = 0
End Function