在Shell32.DLL动态链接库中包括一个函数Shell_NotifyIconA()可通知Windows在任务条右下角加入一个小图标,

解决方案 »

  1.   

    系统托盘
    它是通过调用shellapi函数shell_NotifyIcon()来完成的。Shell_NotifyIcon函数的TNotifyIconData结构定义如下:
    cbsize:结构的尺寸;
    Wnd :应用程序的句柄,一般为=Handle;
    uID : 应用程序定义的在托盘中图标的ID,可以任意选择,一般为0;
    uFlags :指定可用项,有NIF_ICON、NIF_TIP、NIF_MESSAGE;
    uCallbackMessage :指定回调函数;
    hIcon :指定托盘图标,一般为=Icon.Handle;
    szTip :提示信息;
    Shell_NotifyIcon函数的使用:Shell_NotifyIcon(dwMessage:Cardinal,pData:pNotifyIconData):
    dwMessage:要执行操作的标志ID[NIM_ADD、NIM_DELETE、NIM_MODIFY];
    pData:上面所写的结构的指针[@nid];
    添加系统托盘的全部过程:
    1.自定义消息:Const WM_MYMSG=WM_USER+100;
    2.定义消息回调函数:procedure MyFunc(var msg:Tmessage);message WM_MYMSG;
    3.在FormCreate函数中添加结构成员,然后调用函数;
    4.隐藏窗体:在FormPaint函数中调用Hide方法;
    5.在FormClose函数中调用API函数取消托盘程序;
      

  2.   

    Look:// 也可去搜索呀
    unit Unit_Shell;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,ShellAPI, ExtCtrls, Menus;Const
       WM_TRayMessage=WM_user+10;type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        aaa1: TMenuItem;
        bbb1: TMenuItem;
        ccc1: TMenuItem;
        ddd1: TMenuItem;
        Image1: TImage;
        Procedure WMTrayMessage(Var Msg:TMessage);Message WM_Traymessage;
        Procedure AppMiniMized(Sender:TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      Nid:TNotifyIconData;implementation{$R *.dfm}
    Procedure Tform1.WMTrayMessage(Var Msg:TMessage);
      Var
        PMouse:TPoint;
     Begin
       If Msg.LParam=WM_LButtonDBLclk Then
         Begin
            ShowWindow(Application.Handle,SW_Show);
            Application.Restore ;
         End
       Else If Msg.LParam=WM_RButtonDown Then
         Begin
           GetCursorPos(PMouse);
           PoPupMenu1.Popup(PMouse.X,Pmouse.Y)
         End;
     End;Procedure TForm1.AppMiniMized(Sender:TObject);
     Begin
       Nid.cbSize:=Sizeof(TNotifyIconData);
       Nid.hIcon:=Image1.Picture.Icon.Handle ;
       Nid.szTip:='测试系统';
       Nid.uCallbackMessage:=WM_TrayMessage;
       Nid.uFlags:=Nif_Icon or Nif_Message OR Nif_Tip;
       Nid.Wnd:=Handle;
       Nid.uID:=0;
       Shell_NotifyIcon(Nim_add,@Nid);
       ShowWindow(Application.Handle,SW_Hide);
     end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMinimize:=AppMiniMized;
      AppMiniMized(Nil);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Shell_NotifyIcon(Nim_Delete,@Nid);
    end;end.
      

  3.   

    这是我原来写的程序 Const WM_ICONCALLBACKMESSAGE=WM_USER+0;
      tind:TNotifyIconData;
        procedure  WndProc (var Message:TMessage);message WM_iconcallbackMessage;   //这里是定义
    tind.cbSize:=SizeOf (TNotifyIconData);
      tind.Wnd:=form1.Handle;
      tind.hIcon:=Application.Icon.Handle;
      tind.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
      tind.uID:=0;
      tind.szTip:='测试';
      tind.uCallBackMessage:=WM_ICONCALLBACKMESSAGE;
    shell_NotifyIcon (NIM_ADD,@tind);
    shell_NotifyIcon (NIM_delete,@tind); procedure  WndProc (var Message:TMessage);   //这里是截获消息if msg.LParam=WM_LButtonDown then           //如果是左健
        begin
          ShowWindow(Application.Handle,SW_Show);
          Application.Restore;
        end
      else if msg.LParam=WM_RButtonDown then   //如果是右健
        begin
          GetCursorPos(p);
          PopupMenu1.Popup(p.x,p.y);
        end;