Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleMove a form when the user clicks and drags its border
Keywordsmove form, drag, border
CategoriesAPI
 
Subclass the form and look for the WM_NCLBUTTONDOWN message. When the wParam indicates a border mouse down, send the form the WM_NCLBUTTONDOWN message with the HTCAPTION parameter to begin a form move. Call the form's original WindowProc to process the message only if the code doesn't do this move.
 
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Static num As Long

Const WM_NCLBUTTONDOWN = &HA1
Const HTBORDER = 18
Const HTBOTTOM = 15
Const HTBOTTOMLEFT = 16
Const HTBOTTOMRIGHT = 17
Const HTCAPTION = 2
Const HTCLOSE = 20
Const HTGROWBOX = 4
Const HTLEFT = 10
Const HTMAXBUTTON = 9
Const HTMINBUTTON = 8
Const HTRIGHT = 11
Const HTSYSMENU = 3
Const HTTOP = 12
Const HTTOPLEFT = 13
Const HTTOPRIGHT = 14

Dim skip_it As Boolean

    If msg = WM_NCLBUTTONDOWN Then
        Select Case wParam
            Case HTBORDER, HTBOTTOM, _
              HTBOTTOMLEFT, HTBOTTOMRIGHT, _
              HTLEFT, HTRIGHT, HTTOP, _
              HTTOPLEFT, HTTOPRIGHT, HTGROWBOX
                ' Move the form.
                ReleaseCapture
                SendMessage hwnd, WM_NCLBUTTONDOWN, _
                    HTCAPTION, ByVal 0&
                skip_it = True
        End Select
    End If
    num = num + 1

    ' Call the original WindowProc.
    If Not skip_it Then
        NewWindowProc = CallWindowProc( _
            OldWindowProc, hwnd, msg, wParam, _
            lParam)
    End If
End Function
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated