Results 1 to 2 of 2

Thread: Subclassing Window Maximize?

  1. #1
    Guest
    I need to subclass the maximize message, if there is any.

    Please enlighten me on any MAXIMIZE messages (and I already know about WindowState).

    Thanks,

    Jordan

  2. #2
    Guest
    It falls under the WM_SIZE message and wParam specifies the state. In this case, it's WM_MAXIMIZED.

    Code for a Module
    Code:
    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)
    Const WM_SIZE = &H5
    Const SIZE_MAXIMIZED = 2
    Public WndProcOld As Long
    
    Public Function WindowProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
        If wMsg& = WM_SIZE Then
            If wParam = SIZE_MAXIMIZED Then
                MsgBox ("For is maximized")
                'Do code here...
            End If
        End If
        
        WindowProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
        
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Code for Form:
    Code:
    Private Sub Form_Load()
        SubClassWnd Me.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd Me.hwnd
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width