Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleTell when an application is activated or deactivated
Keywordsactivate, deactivate, subclass
CategoriesAPI, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated