Delphi防止因系统崩溃而丢失任务栏的图标(重建托盘图标)


本文整理自网络,侵删。

 很多软件都在系统托盘区添加了图标,可以有时当Explorer.exe莫名的崩溃以后,程序在任务栏的图标就消失了,
对于有些在任务栏隐藏了的软件来说,就没法控制了。原因是Explorer重新载入以后会重建任务栏,
但大多数软件并不知道任务栏已经重建,所以没有及时重新画自己在任务栏的图标。
当任务栏建立的时候会向系统内所有顶级窗口发出一条消息:WM_TASKBARCreateD,我们只需要捕捉这个消息,
并重建任务栏图标即可。不过这是一条任务栏自定义的消息,所以需要用RegisterWindowMessage在自己的程序里注册该消息。

unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs; type  TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private    procedure WndProc(var msg: Tmessage); override; //任务栏恢复消息(继承)  public    { Public declarations }  end; var  Form1: TForm1;  TaskBarMSG: Dword; //任务栏恢复消息 implementation {$R *.dfm} { TForm1 } procedure TForm1.WndProc(var msg: Tmessage); //任务栏恢复消息begin  if msg.msg = TaskBarMSG then SetTryico(Handle, Icon.Handle, AppTray); //重设ICON  inherited WndProc(msg);end;end; procedure TForm1.FormCreate(Sender: TObject);begin  TaskBarMSG := RegisterWindowMessage('HTaskBarCreated'); //注册任务栏恢复消息end; end.

编译这个程序,然后用任务管理器或其他工具中止Explorer.exe,可以看到在Explorer重新载入的时候,
本程序在任务栏的图标又重现了。

相关阅读 >>

Delphi opendialog控件用法

Delphi中控制扫描仪

Delphi 播放声音 采用 异步方式,比较流畅

Delphi xe 使用savestate保存firemonkey状态的示例

Delphi自动以管理员身份在vista 和 windows7 下运行程序

Delphi getfilehashmd5

Delphi如何判断一个combobox是否处于下拉状态

Delphi 链接文件名合并

Delphi dbgrid应用

Delphi 判断两个时间差是否在一个指定范围内 -withinpastyears、withinpastmonths、withinpastweeks、withinpastdays

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...