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
 
 
 
 
 
 
TitleSubclass to see when a control is about to become visible or invisible
Keywordscontrol, visible, invisible, hide, event, subclass
CategoriesAPI, Tips and Tricks
 
Subclass the control and watch for the WM_SHOWWINDOW message.
 
' Look for WM_SHOWWINDOW.
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Const WM_NCDESTROY = &H82
Const SW_OTHERUNZOOM = 4
Const SW_OTHERZOOM = 2
Const SW_PARENTCLOSING = 1
Const SW_PARENTOPENING = 3
Const WM_SHOWWINDOW = &H18

Dim reason As String

    ' If we're being destroyed,
    ' restore the original WindowProc.
    If msg = WM_NCDESTROY Then
        SetWindowLong _
            hwnd, GWL_WNDPROC, _
            OldWindowProc
    End If

    If msg = WM_SHOWWINDOW Then
        ' See why the visibility is changing.
        Select Case lParam
            Case SW_OTHERZOOM
                reason = "SW_OTHERZOOM"
            Case SW_PARENTCLOSING
                reason = "SW_PARENTCLOSING"
            Case SW_PARENTOPENING
                reason = "SW_PARENTOPENING"
            Case WM_SHOWWINDOW
                reason = "WM_SHOWWINDOW"
            Case Else
                reason = "<unknown>"
        End Select

        Form1.VisibleEvent CBool(wParam), reason
    End If

    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
Note that I could not get lParam to return any value other than 0.

For more information on subclassing including important precautions, see Tutorial: Subclassing.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated