Solved

Drag mutliple forms at same time

Posted on 2004-09-22
8
238 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

12 Experts available now in Live!

Get 1:1 Help Now