苦!我已试过无数消息了。都没有反应!试过之后再来发言哦,不要想当然的说什么paint事件、……事件。

解决方案 »

  1.   

    我正在写vcl组件,该组件需要在窗体位置改变时处理代码。
      

  2.   

    会得到 WM_MOVING 事件
    如:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;type
      TForm1 = class(TForm)
        StatusBar1: TStatusBar;
      private
        { Private declarations }
        procedure FormMove(var msg:TMessage);message WM_MOVING;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.FormMove(var msg: TMessage);
    var
      Rect:^Trect;
    begin  Rect:=Pointer(msg.LParam);
      StatusBar1.Panels.Items[0].Text:='Left='+inttostr(Rect.Left);
      StatusBar1.Panels.Items[1].Text:='Top='+inttostr(Rect.Top);
      StatusBar1.Panels.Items[2].Text:='Right='+inttostr(Rect.Right);
      StatusBar1.Panels.Items[3].Text:='Bottom='+inttostr(Rect.Bottom);end;end.
      

  3.   

    拜托,不要说“至少”。自己试一下就知道理想于现实有多少差距。WM_PAINT
    没有被触发。really。不信自己看了。
      

  4.   

    控件不会收到任何事件,你的问题可以这样解决:
      TMyControl = class(TCustomControl)
        private
          OldProc: TWndMethod;
          procedure MyWndProc(var Message: TMessage);
        public
          constructor Create(AOwner: TComponent); override;
          destructor Destroy;override;
          procedure SetMyWndProc;
          procedure ReleaseMyWndProc;
      end;implementation{ TMyControl }constructor TMyControl.Create(AOwner: TComponent);
    begin
      inherited;
    end;destructor TMyControl.Destroy;
    begin
      inherited;
      if Assigned(OldProc) then ReleaseMyWndProc;
    end;procedure TMyControl.MyWndProc(var Message: TMessage);
    begin
      if Message.Msg = WM_MOVING then
        ShowMessage('');
      if Assigned(OldProc) then OldProc(Message);
    end;procedure TMyControl.ReleaseMyWndProc;
    begin
      if Assigned(OldProc) then 
        parent.WindowProc := OldProc;
    end;procedure TMyControl.SetMyWndProc;
    begin
      OldProc := Parent.WindowProc;
      Parent.WindowProc := MyWndProc;
    end;
      

  5.   

    调用时
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      MyCon := TMyControl.Create(self);
      MyCon.Parent := self;
      MyCon.SetMyWndProc;
    end;
      

  6.   

    cuihl,thanks very much. 我会仔细研究你的方案的,看得出来,你不是庸手!nice。
      

  7.   

    cuihl,我的想法和你的相似,我考虑给parent的onXX事件赋值,但是我担心会出现access invalidate错误,没有尝试。如果真的收不到消息,只能这样了。我很失望。window机制就是这样吗?我不愿相信。
      

  8.   

    window机制没有问题,因为窗口移动时,需要处理的无非就是重新绘制窗口,而所有控件都在窗口内,所以只要窗口绘制成功,控件就没有必要重新画了。假设
    所有控件都要重新绘制,每个控件(窗口)都会有一个WM_PAINT消息,这些消息都会放到线程的消息队列里面,但是Windows会把消息队列里面的所有WM_PAINT消息组合成一个WM_PAINT消息,并组合每个WM_PAINT中的绘制区域,以提高效率。