delphi下怎样实现把exe程序,放到托盘(屏幕右下角)上 谢谢!

解决方案 »

  1.   

    用trayicon或者在csdn上一找以前的帖子,问得太多了
      

  2.   

    看看《Delphi 5编程实例与技巧》这本书!
      

  3.   

    用trayicon,给你一个例子:
    TNotifyIcon 控件1.01 (Build use Delphi 3.0) 说明:作用:往通知区加图标,并可显示,隐藏,修改这个图标. 属性(properties):NotifyIcon:TIcon 欲加在通知区的图标IsVisible:boolean NotifyIcon是否显示的属性Title:string 通知区图标上的提示(最多64个字符)PopupMenu:TPopupMenu 点击通知区图标弹出的菜单PopupStyle:TPopupStyle 弹出菜单的方式TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);方法(methods):ShowIcon 将图标显示在通知区上HideIcon 将通知区上的图标隐藏ModifyIcon 修改通知区上的图标(若IsVisible=false,则不显示出来)Create(AOwner: TComponent); override; 构造方法Destroy; override; 析构方法事件(Events):OnIconMouseDown:procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;(在Mouse点击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,WhoButton=b_Left为点击左键,WhoButton=b_Right为点击右键,)OnIconDoubleClick:procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;(在Mouse双击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,WhoButton=b_Left为双击左键,WhoButton=b_Right为双击右键,)关于Demo:这个演示程序给出了TNotifyIcon的基本用法.包含文件:NotifyIcon.dcrNotifyIcon.pasDemoUnit.pasDemoUnit.dfmPopUnit.pasPopUnit.dfmDemo.dprReadme.txt声明:TNotifyIcon 控件 V 1.011.这是一个免费控件.2.如果你使用它,请发一个E-Mail给作者,谢谢.3我在Delphi3.0 & 4.0 上使用成功4.若要传播它,请完全分发上述8个文件作者 南昌大学计算系95(1) 付昱纲 1998.8.17 21:50E-mail [email protected] NotifyIcon;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,DsgnIntf,ShellApi,ExtCtrls,Menus;constWM_MY_Notify=WM_USER+100;typeTPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);TWhoButton=(b_Left,b_Right);TMouseEvent=procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)of Object;//---------class TNotifyIcon---------TNotifyIcon = class(TCustomControl)private{ Private declarations }FIcon:TIcon;FPda:PNOTIFYICONDATA;FTitle:string;FIconVisible:boolean;FPopupMenu:TPopupMenu;FPopupStyle:TPopupStyle;FOnIconMouseDown:TMouseEvent;FOnIconDoubleClick:TMouseEvent;procedure SetIcon(Icon:TICON);procedure SetTitle(NewTitle:string);function IsShowing:boolean;procedure ShowIt(Accept:boolean);procedure NotifyIconClick(var msg : TMessage);Message WM_My_Notify;protected{ Protected declarations }public{ Public declarations }property IsVisible:boolean read IsShowing write ShowIt;constructor Create(AOwner: TComponent); override;procedure ShowIcon;procedure HideIcon;destructor Destroy; override;procedure ModifyIcon(NewIcon:TIcon);procedure Paint;override;published{ Published declarations }property Height default 33;property Width default 33;property NotifyIcon:TIcon read FIcon write SetIcon;property Title:string read FTitle write SetTitle ;property OnIconDoubleClick:TMouseEventread FOnIconDoubleClick write FOnIconDoubleClick;property OnIconMouseDown:TMouseEventread FOnIconMouseDown write FOnIconMouseDown;property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;property PopupStyle:TPopupStyle read FPopupStylewrite FPopupStyle default [];end;procedure Register;implementationprocedure Register;beginRegisterComponents('MyControl', [TNotifyIcon]);end;procedure TNotifyIcon.ShowIt(Accept:boolean);beginif Accept=true then ShowIconelse HideIcon;end;procedure TNotifyIcon.Paint;beginif (csDesigning in ComponentState) thenbeginWidth:=33;Height:=33;With Canvas dobeginBrush.Color:=clInfoBk;Ellipse(0,0,Self.Width,Self.Height);Font.Color:=clBlue;Brush.Style:=bsClear;FloodFill(5,5,clInfoBk,fsBorder);Brush.Color:=clInfoBk;TextOut(3,Self.Height div 2-6,'Notify');endend;end;procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);var p:TPoint;begintrycase msg.LParam ofWM_LBUTTONDOWN:beginGetCursorPos(p);if Left_Click in FPopupStyle thenbeginSetForegroundWindow(ParentWindow);FPopupMenu.Popup(p.x,p.y);end;if Assigned(FOnIconMouseDown) thenbeginFOnIconMouseDown(Self,p.x,p.y,b_Left);end;end;WM_RBUTTONDOWN:beginGetCursorPos(p);if Right_Click in FPopupStyle thenbeginSetForegroundWindow(ParentWindow);FPopupMenu.Popup(p.x,p.y);end;if Assigned(FOnIconMouseDown) thenbeginFOnIconMouseDown(Self,p.x,p.y,b_Right);end;end;WM_LBUTTONDBLCLK:beginGetCursorPos(p);if Left_DbClick in FPopupStyle thenbeginSetForegroundWindow(ParentWindow);FPopupMenu.Popup(p.x,p.y);end;if Assigned(FOnIconDoubleClick) thenbeginFOnIconDoubleClick(Self,p.x,p.y,b_Left);end;end;
      

  4.   

    强烈建议你使用CoolTrayIcon控件,非常好用(比TrayIcon要好用),要的话给你发一份。
      

  5.   

    WM_RBUTTONDBLCLk:beginGetCursorPos(p);if Right_Click in FPopupStyle thenbeginSetForegroundWindow(ParentWindow);FPopupMenu.Popup(p.x,p.y);end;if Assigned(FOnIconDoubleClick) thenbeginFOnIconDoubleClick(Self,p.x,p.y,b_Right);end;end;end;exceptend;end;function MAKELANGID(p, s:word):Cardinal;beginresult:= (((s)shl 10) or(p));end;constructor TNotifyIcon.Create(AOwner: TComponent);begintryinherited Create(AOwner);FIcon:=TIcon.Create;Height:=36;Width:=36;Visible:=false;FTitle:='Welcome';FIconVisible:=false;//-------------set tray info---------ParentWindow:=TWinControl(AOwner).Handle;New(Fpda);With FPda^ dobeginuCallbackMessage:=WM_MY_Notify;cbsize:=SizeOf(FPda^);uID:=200;wnd:=Handle;uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;end;if (csDesigning in ComponentState) thenbeginif GetUserDefaultLCID = MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) thenApplication.MessageBox('Write by 南昌大学 付昱纲'#13#13'E-mail:[email protected]'#13#13' 1998.8.17','TNotifyIcon 控件 V 1.01',MB_OK+ MB_ICONINFORMATION)elseApplication.MessageBox('Write by NanChang University FuYuGang'#13#13'E-mail:[email protected]'#13#13' 1998.8.17','TNotifyIcon Component V 1.01',MB_OK+ MB_ICONINFORMATION);end;exceptShowMessage('TNotifyIcon Create error');end;end;procedure TNotifyIcon.SetIcon(Icon:TICON);beginFIcon.Assign(Icon);end;procedure TNotifyIcon.ShowIcon;begintryif FIcon.Handle=0 thenbeginExit;end;if FIcon.Handle<>FPda^.hIcon thenHideIcon;if FIconVisible=false thenbeginFPda^.hIcon:=FIcon.handle;FIconVisible:=true;Shell_NotifyIcon(NiM_ADD,FPda);end;exceptShowMessage('TNotifyIcon Show Error ');end;end;procedure TNotifyIcon.HideIcon;begintryif FIconVisible thenbeginFIconVisible:=false;Shell_NotifyIcon(NiM_DELETE,FPda);end;exceptShowMessage('TNotifyIcon Hide Error');end;end;procedure TNotifyIcon.SetTitle(NewTitle:string);beginFTitle:=NewTitle;StrCopy(FPda^.szTip,PChar(FTitle));if FIconVisible thenbeginHideIcon;ShowIcon;end;end;destructor TNotifyIcon.Destroy;begintryHideIcon;Dispose(FPda);FIcon.Free;inherited Destroy;exceptShowMessage('TNotifyIcon Destroy Error');end;end;procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);begintrySetIcon(NewIcon);FPda^.hIcon:=FIcon.handle;if FIconVisible thenShell_NotifyIcon(NiM_Modify,FPda);exceptShowMessage('TNotifyIcon Modify Error');end;end;function TNotifyIcon.IsShowing:boolean;beginResult:=FIconVisible;end;end. --回复得分 0 --Firing_sky 说得很详细了,但是要做通知栏的图标也很简单,应用几个函数(自己写),InstallIcon,UnInstallIcon,IconClick.下面是他们的简单实例:安装图表:procedure TForm1.InstallIcon;varCDIcon:TNotifyICondata;beginnormalIcon:=TIcon.Create;normalIcon:=form1.Icon;CDIcon.cbSize:=sizeof(CDIcon);CDIcon.Wnd:=handle;CDIcon.uID:=ICON_ID;CDIcon.uFlags:= NIF_ICON or NIF_MESSAGE or NIF_TIP;CDIcon.uCallbackMessage:=MI_ICONEVENT;CDIcon.hIcon:=normalicon.Handle;CDIcon.szTip:='光驱控制';Shell_NotifyIcon(NIM_ADD,@CDIcon);end;卸载图标:procedure TForm1.UnInstallIcon;varCDIcon:TNotifyIconData;beginCDIcon.cbSize:=sizeof(CDIcon);CDIcon.Wnd:=Handle;CDIcon.uID:=ICON_ID;Shell_NotifyIcon(NIM_DELETE,@CDIcon);// normalIcon.Free;end;响应click事件:procedure TForm1.IconOnClick(var message:TMessage);varp:TPoint;beginif (message.LParam=WM_LBUTTONDBLCLK) thenShowWindow(handle,SW_SHOW);if (message.LParam=WM_RBUTTONDOWN) thenbeginGetCursorPos(p);pop1.Popup(p.x,p.y);end;end;
      

  6.   

    利用Delphi实现系统状态栏图标吴淑华  系统状态栏图标是指在Windows桌面系统下边的任务栏右边区域内显示的小图标,通常包括时间和输入法,另外,还会包括一些应用程序,如金山词霸或其它一些杀毒软件等的小图标。通常用
    鼠标右键点击这些小图标时会弹出菜单,通过选择这些菜单可以灵活地实现程序的各项功能。 
    下面本文以一个具体的例子,详细介绍一下利用Delphi实现系统状态栏图标的步骤和方法。 
    首先,介绍一下本实例要实现的功能:程序开始运行时会在系统状态栏生成一个小图标,同时会打开应用程序窗口,并在任务栏上显示相应的程序窗口;当用户关闭应用程序窗口时,该窗口
    和任务栏上相应的应用程序窗口都会消失,但应用程序并没有退出;当用户用鼠标左健单击该图标时,会再次打开应用程序窗口,同时在任务栏上显示应用程序窗口;当用户用鼠标右键单击
    系统状态栏中应用程序的小图标时,会弹出菜单,选择菜单项“退出”可以完全退出应用程序。 
    一、 实现步骤 
    1. 创建一个应用程序,在主窗体上增加一个TpopupMenu组件。并为该弹出菜单组件增加菜单项Exit,标题为“退出”。 
    2. 在Uses中添加ShellAPI,因为在系统状态栏中增加图标时需调用ShellAPI函数Shell_NotifyIconA。该函数需要2个参数,其中一个是TnotifyIconDataA结构,需在主窗体中增加
    TnotifyIconDataA类型全局变量ntida。 
    3. 定义消息mousemsg,并编写主窗体的mousemessage消息处理函数,此函数说明在图标上用鼠标左键单击时,会打开应用程序窗口;用鼠标右键单击时,会弹出一个菜单。 
    下面给出步骤2和3的实现代码: 
    unit Unit1; 
    interface 
    uses 
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
    StdCtrls, ExtCtrls, Menus, shellapi; 
     
    const 
    mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件 
    iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用。 
     
    type 
    TForm1 = class(TForm) 
    ...... 
    private 
    //自定义消息处理函数,处理鼠标点击图标事件 
    procedure mousemessage(var message: tmessage); message mousemsg;  
    public 
    { Public declarations } 
    end; 
     
    var 
    Form1: TForm1; 
    ntida: TNotifyIcondataA; //用于增加和删除系统状态图标 
    implementation 
     
    {$R *.DFM} 
     
    procedure TForm1.mousemessage(var message: tmessage); 
    var 
    mousept: TPoint; //鼠标点击位置 
    begin 
    inherited; 
    if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标 
    getcursorpos(mousept); //获取光标位置 
    popupmenu1.popup(mousept.x, mousept.y); //在光标位置弹出菜单 
    end; 
    if message.LParam = wm_lbuttonup then begin //用鼠标左键点击图标 
    //显示应用程序窗口 
    ShowWindow(Handle, SW_SHOW); 
    //在任务栏上显示应用程序窗口 
    ShowWindow(Application.handle, SW_SHOW); 
    SetWindowLong(Application.Handle, GWL_EXSTYLE, 
    not (GetWindowLong(Application.handle, GWL_EXSTYLE) 
    or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW)); 
    end; 
    message.Result := 0; 
    end 
    4. 编辑TForm1.FormCreate(Sender: TObject) 
    应用程序开始运行时,在系统状态栏上生成图标显示,代码如下: 
    procedure TForm1.FormCreate(Sender: TObject); 
    begin 
    ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度 
    ntida.Wnd := handle; //取应用程序主窗体的句柄 
    ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使用 
    ntida.uFlags := nif_icon + nif_tip + nif_message;//指定在该结构中uCallbackMessage、hIcon、szTip参数都有效 
    ntida.uCallbackMessage := mousemsg;//指定的窗口消息 
    ntida.hIcon := Application.Icon.handle;//指定系统状态栏显示应用程序的图标句柄 
    ntida.szTip := 'Icon'; //当鼠标停留在系统状态栏该图标上时,出现该提示信息 
    shell_notifyicona(NIM_ADD, @ntida); //在系统状态栏增加一个新图标 
    end; 
    5. 编辑Tform1.OnClose 
    当用户关闭应用程序窗口时,该窗口和任务栏上相应的应用程序窗口都消失,但程序并没有退出。代码如下: 
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); 
    begin 
    Action := caNone; //不对窗体进行任何操作 
    ShowWindow(Handle, SW_HIDE); //隐藏主窗体 
    //隐藏应用程序窗口在任务栏上的显示 
    ShowWindow(Application.Handle, SW_HIDE); 
    SetWindowLong(Application.Handle, GWL_EXSTYLE, 
    GetWindowLong(Application.handle, GWL_EXSTYLE) 
    or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW); 
    end; 
    6. 编辑弹出菜单Exit 
    当用户点击该菜单时完全退出应用程序。代码如下: 
    procedure TForm1.ExitClick(Sender: TObject); 
    begin 
    //为ntida赋值,指定各项参数 
    ntida.cbSize := sizeof(tnotifyicondataa); 
    ntida.wnd := handle; 
    ntida.uID := iid; 
    ntida.uFlags := nif_icon + nif_tip + nif_message; 
    ntida.uCallbackMessage := mousemsg; 
    ntida.hIcon := Application.Icon.handle; 
    ntida.szTip := 'Icon'; 
    shell_notifyicona(NIM_DELETE, @ntida); //删除已有的应用程序图标 
    Application.Terminate; //中断应用程序运行,退出应用程序 
    end; 
    二、 技术要点 
    1.程序中在增加或删除系统状态栏图标时,需调用ShellAPI函数Shell_NotifyIconA,该函数有两个参数,其中一个是TnotifyIconDataA结构,在前面的程序注释中已经对其进行了介绍;另
    一个参数是dwMessage,通过不同的取值表示是增加图标、修改图标或删除图标。 
    2.通过调用一组API函数,实现在任务栏上显示或隐藏应用程序窗口。这些函数分别为ShowWindow、SetWindowLong和GetWindowLong。其中,ShowWindow用于设置指定窗口的显示状态;
    SetWindowLong和GetWindowLong分别用于改变和检索指定窗体的一个属性。 
      

  7.   

    下载trayicon,用它做起来简单
      

  8.   

    to AustinLei(夜半琴声) 
    你的那个 cooltray...的控件寄给我吧
    谢谢
    email: [email protected]