|
-
Aug 21st, 2001, 12:58 AM
#1
Thread Starter
Addicted Member
SetWindowsHookEx
Hiyas,
I've been trying to capture a certain reoccuring message from a program using GetMessage, although I've been told you can't use GetMessage outside the VB program's own form.
So, I'm now trying to intercept and retrieve this message using SetWindowsHookEx...how can I do it?
Thanks for any help,
-Git
-
Aug 21st, 2001, 01:04 AM
#2
Fanatic Member
Code:
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
'In a form, called Form1
Private Sub Form_Load()
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the windows-hook
UnhookWindowsHookEx hHook
End Sub
-
Aug 21st, 2001, 01:17 AM
#3
Thread Starter
Addicted Member
Hiya,
Thanks, but I couldn't really understand that code...
I didn't really explain myself too well : basically, I've located a message using Spy++, and now I'm trying to retrieve it in VB. I know the wParam (0), lParam (1), and it's registered as 'Registered:"wm_offline"'. The message 'address' (not sure what you'd call it, I'm an amatuer at this) is 0x???? (the '????' part changes everytime I load it).
What I'm trying to do is retrieve the 'address' (0x????) part of the message, and convert it to a Long variable. I've figured out how to replicate the actual message and send it to another program, but since the 'address' from the other program changes everytime it loads (or I boot up, not sure...) I need to locate this 'address' from the other program's message first before I can change the message and pass it on using my program...
-Git
-
Aug 21st, 2001, 01:45 AM
#4
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|