|
-
Feb 25th, 2001, 02:18 PM
#1
Thread Starter
Lively Member
Hi i need to intercerpt a wm_active message but i need to find out one of its parameters value -wParam whether it is wa _inactive . Can you tell me how to do it ?
-
Feb 25th, 2001, 02:40 PM
#2
Frenzied Member
Subclass your form"
Code:
'in module
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
If uMsg = WM_ACTIVATE Then
If wParam = WA_INACTIVE Then
'do something
End If
End If
End Function
'in form
Private Sub Command1_Click()
SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
-
Feb 25th, 2001, 02:41 PM
#3
Frenzied Member
Almost Forgot:
PHP Code:
Public Const WM_ACTIVATE = &H6
Public Const WA_INACTIVE = 0
Public Const WA_ACTIVE = 1
Public Const WA_CLICKACTIVE = 2
-
Feb 25th, 2001, 02:50 PM
#4
WA_INACTIVE = 0 so you really don't need to declare it.
-
Feb 25th, 2001, 02:57 PM
#5
Also, your subclas routine might cause problems, because you didn't return the default procedure when your App quits.
Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = 1 And wParam = 0 Then
'Do something
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Add to a Form
Code:
Private Sub Form_Load()
SubClassWnd hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub
-
Feb 26th, 2001, 10:10 AM
#6
Thread Starter
Lively Member
Hi actually i am using a third party software called Spyworks to detect wm_active message . What i am doing is detecting this message when the user switches active window ( which maybe between any 2 windows other than the VB form) . So how can I alter the code so that it can detect whether the message is a wa_inactive .
-
Jul 29th, 2001, 11:28 AM
#7
New Member
your codes are good work.
SetWindowLong() needs a specific window handle.
I want to subclass any window is acitve.
How can I hook any window?
Originally posted by Megatron
Also, your subclas routine might cause problems, because you didn't return the default procedure when your App quits.
Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = 1 And wParam = 0 Then
'Do something
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Add to a Form
Code:
Private Sub Form_Load()
SubClassWnd hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub
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
|