DELPHI窗口最小化和还原事件捕获


本文整理自网络,侵删。

 

constWM_TRAYNOTIFY=WM_USER+1;//定义通知消息...private    { Private declarations }    procedure SysCommand(var SysMsg: TMessage); message WM_SYSCOMMAND; //托盘    procedure WMNID(var msg:TMessage); message WM_TRAYNOTIFY;  //托盘操作...var  FrmLogin: TFrmLogin;  nd0 :NotifyIconData; //托盘implementation{$R *.dfm}procedure TFrmLogin.SysCommand(var SysMsg: TMessage);begin   if (SysMsg.WParam = SC_MINIMIZE) or (SysMsg.WParam = SC_CLOSE) then // 当最小化与关闭 时    begin      SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW);      Hide; // 在任务栏隐藏程序      // 在托盘区显示图标      with nd0 do      begin        cbSize := SizeOf(TNotifyIconData);        Wnd := Handle;        uID := 0;        uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;        uCallBackMessage := WM_TRAYNOTIFY;        hIcon := Application.Icon.Handle;        szTip := csMainRitle;      end;      Shell_NotifyIcon(NIM_ADD, @nd0); // 在托盘区显示图标    end   else   inherited;  //end;end;Procedure TFrmLogin.WMNID(var msg:TMessage); //托盘操作var  mousepos: TPoint;begin  GetCursorPos(mousepos); //获取鼠标位置  case msg.LParam of    WM_LBUTTONUP: // 在托盘区点击左键后    begin      Self.Visible := not Self.Visible; // 显示主窗体与否      Shell_NotifyIcon(NIM_DELETE, @nd0); // 显示主窗体后删除托盘区的图标      SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW); // 在任务栏显示程序    end;    WM_RBUTTONUP: pm1.Popup(mousepos.X, mousepos.Y); // 弹出菜单   end;end;

相关阅读 >>

Delphi byte数组根据utf8 转换为string

Delphi 正则表达式tperlregex 详解

Delphi研究之驱动开发篇(一)--实现原理

Delphi 中字符串比较函数对比

Delphi 62进制转10进制

Delphi 调用批处理

Delphi 关于 tregex.split()

Delphi 生成txt 指定带bom

Delphi 根据分割符只取最后的值

Delphi 自动复制到指定目录的代码

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



打赏

取消

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

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

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

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

评论

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