[Migrated content. Thread originally posted on 13 December 2004]
I am looking for a way to keep floating windows together. In other words, if the user chooses to move a window, I want to move other windows programatically at that time (to the same place that the user moves the window).After researching the manual set and contacting support, it doesn't seem like there is an event that occurs when a window is moved or a way to keep windows together without using subwindows. I cannot use subwindows for a variety of reasons. So, I started looking for a Windows API solution.
I found some VB code that looks to accomplish what I want by calling the Windows API (shown below). I'm currently working through this to see if this works, but so far I haven't been able to get it to work. Does anyone know a better way to accomplish this? Has anyone done something like this before? Any help would be appreciated.
Thanks,
Rob
Public OldWindowProc As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As WINDOWPOS) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type
' 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