Delphi:最小化系统托盘中的应用程序 [英] Delphi: Minimize application to systray

查看:124
本文介绍了Delphi:最小化系统托盘中的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想最小化到系统托盘而不是任务栏的Delphi应用程序。

I want to minimize a Delphi application to the systray instead of the task bar.

必要的步骤似乎如下:


  1. 创建图标,然后应将其显示在系统托盘中。

  2. 当用户单击[-]以最小化应用程序时,请执行以下操作:

  1. Create icon which should then be displayed in the systray.
  2. When the user clicks the [-] to minimize the application, do the following:

  1. 隐藏表单。

  2. 将图标(步骤1)添加到系统托盘中。 / li>
  3. 隐藏/删除任务栏中的应用程序条目。


  • 当用户双击时应用程序在系统托盘中的图标,请执行以下操作:

  • When the user double-clicks the application's icon in the systray, do the following:


    1. 显示表单。

    2. 再次取消最小化应用程序

    3. 如果将 WindowState设置为 WS_Normal,则将 WindowState设置为 WS_Normal。

    4. 隐藏/删除应用程序中的图标

    1. Show the form.
    2. Un-minimize the application again and bring it to the front.
    3. If "WindowState" is "WS_Minimized" set to "WS_Normal".
    4. Hide/delete the application's icon in the systray.


  • 当用户终止应用程序时,请执行以下操作:

  • When the user terminates the application, do the following:


    1. 隐藏/删除应用程序的图标在系统托盘中。


  • 就是这样。是吗?

    如何在Delphi中实现呢?

    How could one implement this in Delphi?

    我找到了以下代码,但我不知道不知道它为什么起作用。它没有遵循我上面描述的步骤...

    I've found the following code but I don't know why it works. It doesn't follow my steps described above ...

    unit uMinimizeToTray;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ShellApi;
    
    const WM_NOTIFYICON = WM_USER+333; 
    
    type
      TMinimizeToTray = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure CMClickIcon(var msg: TMessage); message WM_NOTIFYICON;
      private
        { Private-Deklarationen }
      public
        { Public-Deklarationen }
      end;
    
    var
      MinimizeToTray: TMinimizeToTray;
    
    implementation
    
    {$R *.dfm}
    
    procedure TMinimizeToTray.CMClickIcon(var msg: TMessage);
    begin
      if msg.lparam = WM_LBUTTONDBLCLK then Show;
    end;
    
    procedure TMinimizeToTray.FormCreate(Sender: TObject);
    VAR tnid: TNotifyIconData;
        HMainIcon: HICON;
    begin
      HMainIcon := LoadIcon(MainInstance, 'MAINICON');
      Shell_NotifyIcon(NIM_DELETE, @tnid);
      tnid.cbSize := sizeof(TNotifyIconData);
      tnid.Wnd := handle;
      tnid.uID := 123;
      tnid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      tnid.uCallbackMessage := WM_NOTIFYICON;
      tnid.hIcon := HMainIcon;
      tnid.szTip := 'Tooltip';
      Shell_NotifyIcon(NIM_ADD, @tnid);
    end;
    
    procedure TMinimizeToTray.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action := caNone;
      Hide;
    end;
    
    end.
    


    推荐答案

    我建议使用CoolTrayIcon。作者已经解决了与托盘图标有关的所有问题。它免费提供源代码和示例,并且经过了调试。

    I would recommend using CoolTrayIcon. The author has already worked out all the issues involved with tray icons. Its free with source and examples and very debugged.

    http ://subsimple.com/delphi.asp

    这篇关于Delphi:最小化系统托盘中的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆