窗体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 事件添加即可