PDA

Click to See Complete Forum and Search --> : Check Parameter of a wm_active message


eng70640
Feb 25th, 2001, 01:18 PM
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 ?

Vlatko
Feb 25th, 2001, 01:40 PM
Subclass your form"

'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

Vlatko
Feb 25th, 2001, 01:41 PM
Almost Forgot:

Public Const WM_ACTIVATE = &H6
Public Const WA_INACTIVE = 0
Public Const WA_ACTIVE = 1
Public Const WA_CLICKACTIVE = 2

Feb 25th, 2001, 01:50 PM
WA_INACTIVE = 0 so you really don't need to declare it.

Feb 25th, 2001, 01:57 PM
Also, your subclas routine might cause problems, because you didn't return the default procedure when your App quits.

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

Private Sub Form_Load()
SubClassWnd hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub

eng70640
Feb 26th, 2001, 09:10 AM
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 .

dobiho
Jul 29th, 2001, 11:28 AM
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.

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

Private Sub Form_Load()
SubClassWnd hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub