| Public MsgNames As New Collection
Public Sub LoadMsgNames()
Static done_before As Boolean
    If done_before Then Exit Sub
    done_before = True
    
    MsgNames.Add "WM_NULL", "0"
    MsgNames.Add "WM_CREATE", "1"
    MsgNames.Add "WM_DESTROY", "2"
    ' LOTS of code omitted...
End Sub
Public Function MsgName(ByVal num As Long) As String
    On Error Resume Next
    MsgName = MsgNames(Hex$(num))
    If Err.Number = 0 Then Exit Function
    If num >= 0 And num < WM_USER Then
        MsgName = "Range 1 message reserved for Windows"
    ElseIf num >= WM_USER And num <= &H7FFF Then
        MsgName = "Reserved for private window classes"
    ElseIf num >= &H8000 And num <= &HBFFF Then
        MsgName = "Range 3 message reserved for Windows"
    ElseIf num >= &H8000 And num <= &HBFFF Then
        MsgName = "String message for use by applications"
    Else
        MsgName = "Unknown message" & Str$(num)
    End If
End Function
' Display message names.
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
    ' Load the message names.
    LoadMsgNames
    ' Display the message's name.
    Debug.Print Hex$(msg) & ": " & MsgName(msg)
    ' If we're being destroyed,
    ' restore the original WindowProc.
    If msg = WM_NCDESTROY Then
        SetWindowLong _
            hwnd, GWL_WNDPROC, _
            OldWindowProc
    End If
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function |