让子窗口跟这主窗口移动

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值