我想把现有的程序做成运行后自动以一个图标出现在任务栏的右下角,在图标上使用右键菜单来退出程序,请高手们指教,有没有现在成的代码提供以参考??

解决方案 »

  1.   

    http://community.csdn.net/Expert/TopicView1.asp?id=3566802
      

  2.   

    //我原来编写的一个程序的部分源程序,给你吧(部分程序,自己动手写写看)unit Main_Unit;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus, StdCtrls, Buttons, ExtCtrls, ShellApi,ImgList,inifiles;const
      menuMsg=WM_USER+1;...
    private
        { Private declarations }
        nid:TNotifyIconData;
        procedure WmSysCommand(var Msg:TWMSysCommand);message WM_SYSCOMMAND;
        procedure addIcon;
        procedure delIcon;
        procedure IconTray(var Msg:TMessage);message menuMsg;    ...
    procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      nid.cbSize:=sizeof(TNotifyIconData);
      nid.Wnd:=Handle;
      nid.uID:=0;
      shell_NotifyIcon(NIM_DELETE,@nid);
    end;procedure TfrmMain.WmSysCommand(var Msg: TWMSysCommand);
    begin
      if Msg.CmdType=SC_MINIMIZE then
      begin
        addIcon;
        self.Hide;
      end
      else
        inherited;
    end;procedure TfrmMain.addIcon;
    begin
      nid.cbSize:=sizeof(TNotifyIconData);
      nid.Wnd:=handle;
      nid.uID:=0;
      nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
      nid.uCallbackMessage:=menuMsg;
      nid.hIcon:=Application.Icon.Handle;
      nid.szTip:='AutoMouse Clicked';
      shell_NotifyIcon(NIM_ADD,@nid);
    end;procedure TfrmMain.delIcon;
    begin
      ShowWindow(Application.Handle,SW_SHOW);
      Application.Restore;
      self.Show;
      SetForegroundWindow(Handle);
      shell_NotifyIcon(NIM_DELETE,@nid);
    end;//处理托盘区域消息
    procedure TfrmMain.IconTray(var Msg: TMessage);
    var
      p:TPoint;
    begin
      if Msg.LParam=WM_RBUTTONUP then
      begin
        GetCursorPos(p);
        SetForegroundWindow(Handle);
        pm.Popup(p.X,p.Y);
      end;
      if Msg.LParam=WM_LBUTTONUP then
        delIcon;
      inherited;
    end;
      

  3.   

    给你解释一下楼上兄弟的思路:创建托盘,然后劫获最小化句柄事件完成,如果是点击关闭的化可以用WM_CLOSE句柄,如果你还需要用右键的话,还要用TPopupMenu控件....
      

  4.   

    按上面的代码写后运行出现以下错误:undeclared indentifier 'Handle'
    undeclared indentifier 'pprogamversion'
    undeclared indentifier 'ucallbackmessage'
    undeclared indentifier 'WM_ICONMESSAGE'
    unsafe code'@ operator'
      

  5.   

    就是最托盘程序嘛
    procedure TFrmmain.WMSysCommand(var Message:TMessage);
    var
       lpData:PNotifyIconData;
    begin
      if Message.WParam = SC_ICON then
      begin
         //如果用户最小化窗口则将窗口隐藏并在任务栏上添加图标
         lpData := new(PNotifyIconDataA);
         lpData.cbSize := 88;
         //SizeOf(PNotifyIconDataA);
         lpData.Wnd := Frmmain.Handle;
         lpData.hIcon := Frmmain.Icon.Handle;
         lpData.uCallbackMessage := WM_BARICON;
         lpData.uID :=0;
         lpData.szTip := 'EDISvr1.0';
         lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
         Shell_NotifyIcon(NIM_ADD,lpData);
         dispose(lpData);
         Frmmain.Visible := False;
      end
      else
      begin
         //如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。
         DefWindowProc(Frmmain.Handle,Message.Msg,Message.WParam,Message.LParam);
      end;
    end;procedure TFrmmain.WMBarIcon(var Message:TMessage);
    var
       lpData:PNotifyIconData;
       Pt: TPoint;
    begin
      case Message.LParam of
           WM_LBUTTONDOWN:
           begin
             //如果用户点击任务栏图标则将图标删除并回复窗口。
              lpData := new(PNotifyIconDataA);
              lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);
              lpData.Wnd := Frmmain.Handle;
              lpData.hIcon := Frmmain.Icon.Handle;
              lpData.uCallbackMessage := WM_BARICON;
              lpData.uID :=0;
              lpData.szTip :='sdffsd';
              lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
              Shell_NotifyIcon(NIM_DELETE,lpData);
              dispose(lpData);
              Frmmain.Visible := True;
           end;
           WM_RBUTTONDOWN:    //当点击右键时,弹出快捷菜单
           begin
              lpData := new(PNotifyIconDataA);
              SetForeGroundWindow(lpData.Wnd);
              GetCursorPos(Pt);
              Popupmenu.Popup(pt.x, pt.y);
           end;
      end;
    end;    判断消息就可以了
      

  6.   

    先声明:这个是别人的程序,我以前COPY下来的
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,shellapi, Menus;
    const  
           WM_TrayMessage=WM_User+100;
    type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        N11: TMenuItem;
        N21: TMenuItem;
        procedure FormCreate(Sender: TObject);
           protected  
               procedure  AppMinimized(Sender:  TObject);  
               procedure  WMTrayMessage(var  msg:TMessage);message  WM_TrayMessage;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
       NID:TNotifyIconData;
    implementation{$R *.dfm}
     procedure  TForm1.AppMinimized(Sender:  TObject);  
    begin  
     NID.cbSize:=SizeOf(TNotifyIconData);  
       NID.hIcon:=Application.Icon.Handle;
       NID.szTip:=  '工程一  ';  
       NID.uCallbackMessage:=WM_TrayMessage;  
       NID.uFlags:=NIF_ICON  or  NIF_MESSAGE  or  NIF_TIP;  
       NID.uID:=0;  
       NID.Wnd:=Handle;  
       Shell_NotifyIcon(NIM_ADD,@NID);  
       ShowWindow(Application.Handle,SW_Hide);  
     
    end;
    procedure  TForm1.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);
               PopupMenu1.Popup(p.x,p.y);  
           end;  
    end;  
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Application.OnMinimize:=AppMinimized;  
       AppMinimized(nil);
    end;end.
      

  7.   

    忘记还有一句代码了
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    Shell_NotifyIcon(NIM_DELETE,@NID);
    end;
      

  8.   

    trayicon吧,简单方便而且可以很容易实现特效