窗体移动时,窗体上的控件会收到什么消息呢? 苦!我已试过无数消息了。都没有反应!试过之后再来发言哦,不要想当然的说什么paint事件、……事件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我正在写vcl组件,该组件需要在窗体位置改变时处理代码。 会得到 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. 拜托,不要说“至少”。自己试一下就知道理想于现实有多少差距。WM_PAINT没有被触发。really。不信自己看了。 控件不会收到任何事件,你的问题可以这样解决: 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; 调用时procedure TForm1.FormCreate(Sender: TObject);begin MyCon := TMyControl.Create(self); MyCon.Parent := self; MyCon.SetMyWndProc;end; cuihl,thanks very much. 我会仔细研究你的方案的,看得出来,你不是庸手!nice。 cuihl,我的想法和你的相似,我考虑给parent的onXX事件赋值,但是我担心会出现access invalidate错误,没有尝试。如果真的收不到消息,只能这样了。我很失望。window机制就是这样吗?我不愿相信。 window机制没有问题,因为窗口移动时,需要处理的无非就是重新绘制窗口,而所有控件都在窗口内,所以只要窗口绘制成功,控件就没有必要重新画了。假设所有控件都要重新绘制,每个控件(窗口)都会有一个WM_PAINT消息,这些消息都会放到线程的消息队列里面,但是Windows会把消息队列里面的所有WM_PAINT消息组合成一个WM_PAINT消息,并组合每个WM_PAINT中的绘制区域,以提高效率。 求 delphi中 大图中查找是否有小兔的代码 主從表的記錄復制問題 引用DLL后,程序退出有报错,DLL会受传入的参数类型不同而影响!为什么,大家帮帮忙嘛! 请推荐几个下载电子图书的网站?【delphi】 终于决定将软件工程好好的应用一下,欢迎提出好的建议 两个关于BLOB的问题 请问谁知道那里下载一个类似电子表显示时间的控件,含源代码最好。 请教一个ado连接的问题 求救!!! 不要损我 这是我写的一个数据录入的程序的一段总觉的不好,请各位大侠指点一下 combobox除了存text,还能存value?也就是说我选择的是text,但对应的是value。
如: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.
没有被触发。really。不信自己看了。
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;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyCon := TMyControl.Create(self);
MyCon.Parent := self;
MyCon.SetMyWndProc;
end;
所有控件都要重新绘制,每个控件(窗口)都会有一个WM_PAINT消息,这些消息都会放到线程的消息队列里面,但是Windows会把消息队列里面的所有WM_PAINT消息组合成一个WM_PAINT消息,并组合每个WM_PAINT中的绘制区域,以提高效率。