Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drag mutliple forms at same time

Posted on 2004-09-22
8
Medium Priority
?
249 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
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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 86

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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

783 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