Solved

Drag mutliple forms at same time

Posted on 2004-09-22
8
240 Views
Last Modified: 2010-05-02
Hi,

I have 3 vb6 forms

form1
form2
form3


They are all the same size (hight and width)
and on the same position on the screen (top and left)

thats is the forms of lying on top of eachother and only one form can been seen.

Say form1 is on top.. When form1 is draged by the user draging the 'title bar' how can i make the other forms drag behind it.

I.e so when form1 is draged form2 & form3 followit.

Any help greatly appericated.

Ps. The forms are actually MDIchild forms..

Thanks.



0
Comment
Question by:wegwong
  • 2
  • 2
8 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12129015
This requires subclassing Form1 to trap the WM_MOVING message as shown below.  If you want Form2 and Form3 to also resize when Form1 is resized, then you would need to trap and deal with the WM_SIZING message.  Let me know if you need that as well.

Regards,

Idle_Mind

' ------------------------------------------------------------------
' Form1
' ------------------------------------------------------------------
Option Explicit

Private Sub Form_Load()
    Form2.Show
    Form2.Move Me.left, Me.top, Me.Width, Me.Height
    Form3.Show
    Form3.Move Me.left, Me.top, Me.Width, Me.Height
   
    HookWindow Me.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
    HookWindow Me.hwnd
End Sub

' ------------------------------------------------------------------
' Module1
' ------------------------------------------------------------------
Option Explicit

Public Type RECT
   left As Long
   top As Long
   right As Long
   bottom As Long
End Type

Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const GWL_WNDPROC As Long = (-4)
Public Const WM_MOVING = &H216
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOREDRAW = &H8

Public lPrevProc As Long

Public Sub HookWindow(ByVal lHandle As Long)
    If lPrevProc = 0 Then
        lPrevProc = SetWindowLong(lHandle, GWL_WNDPROC, AddressOf HookProc)
    Else
        Call SetWindowLong(lHandle, GWL_WNDPROC, lPrevProc)
    End If
End Sub

Public Function HookProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim rc As RECT

    Select Case uMsg
        Case WM_MOVING
            CopyMemory rc, ByVal lParam, LenB(rc)
           
            If Form2.Visible Then
                SetWindowPos Form2.hwnd, HWND_NOTOPMOST, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE Or SWP_NOREDRAW
            End If
            If Form3.Visible Then
                SetWindowPos Form3.hwnd, HWND_NOTOPMOST, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE Or SWP_NOREDRAW
            End If
    End Select
   
    HookProc = CallWindowProc(lPrevProc, hwnd, uMsg, wParam, lParam)
End Function
0
 
LVL 3

Expert Comment

by:thunder_moose
ID: 12130979
Hi there,

It'll probably be something simple like putting

form2.top = form1.top
form2.left = form1.left
form3.top = form1.top
form3.left = form1.left

In form1's mousedown event, if you're kind of lazy like me. May I ask why you want to do this? Why shouldn't the user be able to see the other two forms? Does the user ever interact with the forms?

Greetings,
tm
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12132715
Hi thunder_moose,

wegwong stated:
>> When form1 is draged by the user draging the 'title bar' how can i make the other forms drag behind it.

The MouseDown, MouseMove and MouseUp events do not fire when you drag a form by its title bar.

Regards,

Idle_Mind
0
 
LVL 3

Expert Comment

by:thunder_moose
ID: 12134303
Even so, my other questions stand. They were actually the reason I posted, I added the rest afterwards.

So I still ask:
May I ask why you want to do this? Why shouldn't the user be able to see the other two forms? Does the user ever interact with the forms?
0
 
LVL 13

Assisted Solution

by:Michael_D
Michael_D earned 250 total points
ID: 12135778
thunder_moose is absolutely right.

I think solution is much easier.

On each form put public sub

Public Sub ActivateMe(ByRef PrevForm As Form)
    Me.Left = PrevForm.Left
    Me.Top = PrevForm.Top
    Me.Height = PrevForm.Height
    Me.Width = PrevForm.Width
    Me.Show
    PrevForm.Hide
End Sub

and when your want make visible for example form2 just call Form2.ActivateMe Me

And there is absolutly no need to use subclassing
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA: Add rows to listbox based on criteria 7 72
How to debug this code 7 56
Question about INSTR  - need to extract data MS ACCESS query 6 53
How does CurrentUser work? 10 31
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now