请看以下代码:
-----------------------------------------------------------------
Dim filePath As String filePath = "X:\XXX\XXX.exe"
If Len(Dir$(filePath)) = 0 Then Exit Sub
Dim pId As Long
pId = Shell(filePath, vbNormalFocus)
If pId = 0 Then Exit Sub
Dim pHnd As Long
pHnd = OpenProcess(SYNCHRONIZE, 0&, pId)
If pHnd = 0 Then Exit Sub
Dim hInstance As Long
'/////////////////////////////////////////////////////////////
hInstance = ???
hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookProc, hInstance, 0&)
'/////////////////////////////////////////////////////////////
Dim lRet As Long
Do
lRet = WaitForSingleObject(pHnd, 0&)
DoEvents
Loop While lRet = WAIT_TIMEOUT
Call UnhookWindowsHookEx(hHook)
Call CloseHandle(pHnd)
-----------------------------------------------------------------
请大家看//////////之间的代码:
1、怎样取得这个 hInstance 呢?
2、我把 hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookProc, hInstance, 0&) 代码中的 hInstance 换成 App.hInstance 也会报错,为什么呢?
-----------------------------------------------------------------
Dim filePath As String filePath = "X:\XXX\XXX.exe"
If Len(Dir$(filePath)) = 0 Then Exit Sub
Dim pId As Long
pId = Shell(filePath, vbNormalFocus)
If pId = 0 Then Exit Sub
Dim pHnd As Long
pHnd = OpenProcess(SYNCHRONIZE, 0&, pId)
If pHnd = 0 Then Exit Sub
Dim hInstance As Long
'/////////////////////////////////////////////////////////////
hInstance = ???
hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookProc, hInstance, 0&)
'/////////////////////////////////////////////////////////////
Dim lRet As Long
Do
lRet = WaitForSingleObject(pHnd, 0&)
DoEvents
Loop While lRet = WAIT_TIMEOUT
Call UnhookWindowsHookEx(hHook)
Call CloseHandle(pHnd)
-----------------------------------------------------------------
请大家看//////////之间的代码:
1、怎样取得这个 hInstance 呢?
2、我把 hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookProc, hInstance, 0&) 代码中的 hInstance 换成 App.hInstance 也会报错,为什么呢?
解决方案 »
- 数据库连接 语法错误
- vb PostMessage hWndParent, WM_CLOSE, 0&, 0&触发 form_unload事件
- 如何识别魔兽版本
- 请教条码参数问题
- 对于mshflexgrid,手填与绑定各有何优缺点呢?请各位讲讲,先谢一下。
- 哪里有免费的FTP上传空间?
- 问:连接数据库的时候出现问题
- 怎么动态增加控件数组,并且这些控件都可以相应事件?
- 救命啊:在VB中将MSHFlexGrid中的数据保存为EXCEL死机(在server上作不死机,但在客户pc机上时总死)
- 请问在VB下怎样取硬盘的序列号??
- 老问题,哪个版本的水晶报表可以实现动态联接啊???
- 请问版主动态创建控件问题
'不过你的情况麻烦点~~~~~~~~~
Private Const GWL_HINSTANCE As Long = -6Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LonghInstance=GetWindowLong(hWnd,GWL_HINSTANCE)
'下面是根据PID获取句柄hWnd(API-Guide里面copy的~~~)
Private Const GW_HWNDNEXT = 2Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongFunction InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn't a child
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
那么必需把回调函数写进dll,然后载入这个DLL,取得hinstance值