Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long, ByVal dwNewLong As Long) As Long
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
Const GWL_WNDPROC = (-4&)
Const WM_MOVE = &H3
Private Const WM_SYSCOMMAND = &H112
Private PrevWndProc1 As Long
Private PrevWndProc2 As Long
Private lngmHwnd1 As Long
Private lngmHwnd2 As Long
Private objmEventRouter As clsSyncMove
Public Sub Init(lngpHwnd1 As Long, lngpHwnd2 As Long, objpSyncMove As clsSyncMove)
Set objmEventRouter = objpSyncMove
PrevWndProc1 = SetWindowLong(lngpHwnd1, GWL_WNDPROC, AddressOf SubWndProc)
lngmHwnd1 = lngpHwnd1
PrevWndProc2 = SetWindowLong(lngpHwnd2, GWL_WNDPROC, AddressOf SubWndProc)
lngmHwnd2 = lngpHwnd2
End Sub
Public Sub Terminate()
SetWindowLong lngmHwnd1, GWL_WNDPROC, PrevWndProc1
SetWindowLong lngmHwnd2, GWL_WNDPROC, PrevWndProc2
End Sub
Private Function SubWndProc(ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Static blnWorking As Boolean
If blnWorking = False Then
blnWorking = True
If Msg = WM_MOVE Then
objmEventRouter.WindowMoved hwnd
End If
blnWorking = False
End If
If hwnd = lngmHwnd1 Then
SubWndProc = CallWindowProc(PrevWndProc1, hwnd, Msg, wParam, lParam)
Else
SubWndProc = CallWindowProc(PrevWndProc2, hwnd, Msg, wParam, lParam)
End If
End Function