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
 
 
 
 
 
TitleMove forms together
DescriptionThis example shows how to move forms together in Visual Basic 6. It subclasses the main form and watches for the WM_WINDOWPOSCHANGING message. When it sees that message, the program moves the satellite forms to stay with the main form.
Keywordsmove forms, subclass, API, WindowProc
CategoriesAPI, Controls
 
The program subclasses the main form and watches for the WM_WINDOWPOSCHANGING message. When it sees that message, the program moves the satellite forms to stay with the main form.
 
' Process messages.
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, lParam As WINDOWPOS) As _
    Long
Const WM_NCDESTROY = &H82
Const WM_WINDOWPOSCHANGING = &H46

    ' If we're being destroyed,
    ' restore the original WindowProc.
    If msg = WM_NCDESTROY Then
        SetWindowLong _
            hwnd, GWL_WNDPROC, _
            OldWindowProc
    Else
        ' See if the window is moving.
        If msg = WM_WINDOWPOSCHANGING Then
            ' The window is moving. Keep the others with it.
            Form2.Move Form1.Left + Form1.Width, Form1.Top _
                - 360
            Form3.Move Form1.Left - Form3.Width, Form1.Top _
                - 360
        End If
    End If

    ' Continue normal processing. VERY IMPORTANT!
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
This program removes the title bar from the satellite forms so you cannot move them directly. You could try to subclass them as well but moving the group as a whole would be more complicated. For example, you might need to be able to ignore WM_WINDOWPOSCHANGING messages while you are moving one of the forms. This example should get you started, though.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated