请问一下,当前windows活动窗口是我的程序,当活动窗口移出,请问,我如何获得这个事件.
解决方案 »
- Class 和 Sub-Class的分别在哪(SB菜鸟)
- paradox数据库中类型为D的日期字段怎么查询呢? 比如查询该日期字段为2004-2-1到2004-12-31之间的记录怎么查呢?
- 请问一个DBGridEh的问题
- 急急!关于报表打印!
- TPrinter实现的打印程序,如何实现打印预览?
- winexec('rundll32.exe rnaui.dll,RnaDial 163',SW_SHOWNORMAL);
- 如何让窗口上的关闭图标变为灰色不可点击?
- 你是否对你现在工作的单位有认同感,归属感?
- 如何对串口通讯程序进行调试,高分相送100分
- 200分请解:用database desktop加密的数据表的解密方法
- 请问一个关于数据库中字段的表示的小问题,谢谢大家!
- 鼠标的消息处理
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
private
procedure m_exit(var Message: TMessage); message CM_MOUSELEAVE;
public
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.m_exit(var Message: TMessage);
begin
Edit1.Text := FormatDateTime('HH:NN:SS.zzz', now());
end;end.
第一,鼠标移出窗体外,就算窗体没有失去焦点也会触发。
第二,鼠标移动到窗体内部的控件上的时候,也会触发。
查了一下系统消息,好像没有离开程序失去焦点的时候发出的消息。
所以,可以做如下考虑:
1,加一个标签判断程序是否被最小化。
2,加一个标签判断鼠标是否在程序窗体外(所有窗体)
3,接收鼠标单击的消息(左右都接收)
然后根据上面两个标签自己判断程序是不是失去了焦点。对系统的消息机制实在不是很在行。希望高手指点。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
procedure WMActivate(var Message: TWMActivate); message WM_ACTIVATE;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.WMActivate(var Message: TWMActivate);
begin
if Message.Active = WA_INACTIVE then Caption:='Inactive'
else Caption:='active'
end;end.
所以应该截获application的消息,而不是mainform的消息。
方法一:
最简便的办法是放一个ApplicationEvents控件(在Additional页),在它的onActivate和onDeactivate事件中做控制。方法二:
设置application.onmessage事件,如:procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MyAppMsg;
end;procedure TForm1.MyAppMsg(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.hwnd = application.Handle then
case Msg.message of
CM_ACTIVATE:
Self.Caption := 'activate';
CM_DEACTIVATE:
Self.Caption := 'inactivate';
end;
end;