|
|
Title | Tell when an application is activated or deactivated |
Keywords | activate, deactivate, subclass |
Categories | API, Windows |
|
|
When it starts, the program calls the SetWindowLong API function to install a new WindowProc.
|
|
Private Sub Form_Load()
OldWindowProc = SetWindowLong( _
hwnd, GWL_WNDPROC, _
AddressOf NewWindowProc)
End Sub
|
|
The new WindowProc looks for the WM_ACTIVATE message. If the wParam parameter is WA_ACTIVE or WA_CLICKACTIVE, the program is activating. Otherwise it is deactivating.
|
|
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
As Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
If msg = WM_ACTIVATE Then
If (wParam = WA_ACTIVE Or wParam = WA_CLICKACTIVE) _
Then
Form1.Caption = "Active!"
Else
Form1.Caption = "Inactive"
End If
End If
NewWindowProc = CallWindowProc( _
OldWindowProc, hwnd, msg, wParam, _
lParam)
End Function
|
|
|
|
|
|