怎样实现托盘区图标?显示、删除图标,能通过图标弹出菜单。

解决方案 »

  1.   

    填充NOTIFYICONDATA结构 。用Shell_NotifyIcon()在托盘上增加、删除或修改图标MSDN上面有的
      

  2.   

    const   WM_TrayMessage=WM_User+100;procedure AppMinimized(Sender: TObject);
    procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;var NID:TNotifyIconData;
    ...
    procedure TFrmMain.WMTrayMessage(var msg:TMessage);
    var
      p:TPoint;
    begin
      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);
        //pmTray.Popup(p.x,p.y);
      end;
    end;procedure TFrmMain.AppMinimized(Sender:TObject);
    begin
      NID.cbSize:=SizeOf(TNotifyIconData);
      NID.hIcon:=Application.Icon.Handle;
      NID.szTip:= 'XXX系统2.0版';
      NID.uCallbackMessage:=WM_TrayMessage;
      NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
      NID.uID:=0;
      NID.Wnd:=Handle;
      if b_IsIco then
         Shell_NotifyIcon(NIM_MODIFY,@NID)
      else
         Shell_NotifyIcon(NIM_ADD,@NID);
      ShowWindow(Application.Handle,SW_Hide);
      b_IsIco:=true;
    end;procedure TFrmMain.FormDestroy(Sender: TObject);
    begin
    Shell_NotifyIcon(NIM_DELETE,@NID);
    end;
      

  3.   

    记得要use ShellApi 这个系统单元哦