procedure WMWindowPosChanged(var Msg: TWMWindowPosChanged); message WM_WindowPosChanged;
const uFlag = SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE or SWP_NOSIZE;
procedure TForm1.WMWindowPosChanged(var Msg: TWMWindowPosChanged);
var
Rect: TRect;
X, Y, Cx, Cy: Integer;
uFlag2: UINT;
begin
inherited;
if Form2 <> nil then //如果子窗体存在
begin
if (Form2.Left - (F1Left + Form1.Width)) < 20 then
begin
GetWindowRect(Form2.Handle, Rect); //获得子窗体的位置
with Msg do
begin
X := Form2.Left + (WindowPos^.x - F1Left); //新X坐标
Y := Form2.Top + (WindowPos^.y - F1Top); //新Y坐标
Cx := WindowPos^.cx; //新宽度
Cy := WindowPos^.cy; //新高度
end;
uFlag2 := uFlag; //移动必要时
if (Rect.Top <> Y) or (Rect.Left <> X) then
uFlag2 := uFlag2 and (not SWP_NOMOVE);
if uFlag <> uFlag2 then //都必要时
SetWindowPos(Form2.Handle, 0, X, Y, Cx, Cy, uFlag2);
end;
end;
F1Top := self.Top;
F1Left := self.Left;
if Form3 <> nil then //如果子窗体存在
begin
if (Form3.Left - (F1Left + Form1.Width)) < 20 then
begin
GetWindowRect(Form3.Handle, Rect); //获得子窗体的位置
with Msg do
begin
X := Form3.Left + (WindowPos^.x - F2Left); //新X坐标
Y := Form3.Top + (WindowPos^.y - F2Top); //新Y坐标
Cx := WindowPos^.cx; //新宽度
Cy := WindowPos^.cy; //新高度
end;
uFlag2 := uFlag; //移动必要时
if (Rect.Top <> Y) or (Rect.Left <> X) then
uFlag2 := uFlag2 and (not SWP_NOMOVE);
if uFlag <> uFlag2 then //都必要时
SetWindowPos(Form3.Handle, 0, X, Y, Cx, Cy, uFlag2);
end;
end;
F2Top := self.Top;
F2Left := self.Left;
end;