您的位置:首页 > 其它

窗体form失去焦点时(非激活状态),发生什么事件

2008-11-18 14:21 459 查看
窗体form失去焦点时(非激活状态),发生什么事件 VCL组件开发及应用
http://www.delphi2007.net/DelphiVCL/html/delphi_20061222233159173.html

由非激活状态变为激活状态是onActivate对吧
那么由激活状态变为非激活状态则对应哪个事件呢?onDeactivate么?我试了好像没用,鼠标点桌面或其他窗口,则form窗体变为非激活,应该触发啥事件?

FormDeactivate

FormDeactivate的触发时机:

when the form transitions from being the active form to another form in the same application becoming the active form.

特别说明:
If activation goes to another application, this event is not triggered.

处理办法:

To determine if another application has become active, Use the TApplication object's OnDeactivate event.

--------------------------------------------------

1、

procedure OnLoseFocus(Sender: TObject);
begin
Form1.Caption := FormatDateTime('HH:MMMM:SS', Now);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
......
@Application.OnDeactivate := @OnLoseFocus;
......
end;

2、可以捕获WM_KillFocus来处理失去焦点的事件

procedure TForm1.NewWindowProc(var Message: TMessage);
begin
if Message.Msg = WM_KillFocus then
Caption := FormatDateTime('HH:MMMM:SS', Now);
OldWindowProc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
......
OldWindowProc := sELF.WindowProc;
Self.WindowProc := NewWindowProc;
......
end;

不好意思,上次给的事件必须是在进程内部的

按照你的意思
你可以添加 ApplicationEvents 控件
然后在OnDeactivate 事件添加即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: