Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving 2 forms, findinf a move event

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
ES
Hi,

I have 2 forms displayed on a screen.

When the user clicks on the title bar and moves one of the forms, I want to be able to 'move' the other form with it.

I cant seem to find an event that is fired while moving a form.

I would expect, maybe , that the forms MouseMove would fire, but it does not.. or even the ReSize event.

Anyone got any ideas on how I can do this?

Thanks,

Rob Donovan.
 
The sample code below assumes two forms. Each form has a timer, Timer1, one them

‘ Code for Form1

Option Explicit

Private Sub Form_Load()
Me.Timer1.Interval = 100
Form2.Show
End Sub

Private Sub Timer1_Timer()
Me.Top = Form2.Top
End Sub

‘ Code for Form2

Option Explicit

Private Sub Form_Load()
Me.Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Me.Top = Form1.Top
End Sub
 
Hook the windows and intercept the move event.
stickywindows_byhook.bas (I forgot where I got it from -sorry):
-----------------------------
Private 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = -4
Private Const WM_MOVE = &H3
Private lpPrevWndProc1 As Long
Private lpPrevWndProc2 As Long
Private hWnd1 As Long
Private hWnd2 As Long

Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If hw = hWnd1 Then
If uMsg = WM_MOVE Then Form2.Move Form1.Left + Form1.Width, Form1.Top
WindowProc = CallWindowProc(lpPrevWndProc1, hw, uMsg, wParam, lParam)
Else
If uMsg = WM_MOVE Then Form1.Move Form2.Left - Form2.Width, Form2.Top
WindowProc = CallWindowProc(lpPrevWndProc2, hw, uMsg, wParam, lParam)
End If
End Function

Private Sub main()
Load Form1
Load Form2

hWnd1 = Form1.hWnd
hWnd2 = Form2.hWnd

lpPrevWndProc1 = SetWindowLong(hWnd1, GWL_WNDPROC, AddressOf WindowProc)
lpPrevWndProc2 = SetWindowLong(hWnd2, GWL_WNDPROC, AddressOf WindowProc)

Form1.Show
Form2.Show
End Sub
------------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top