楼上的,不是创建的一个窗体<br>是2000以后的系统就有这个新功能,要VS7中才有资料,<br><br>右键菜单弹出了,不点就不消失啊,怎么处理?,这个我有理论,就是不能自己做<br><br>气泡提示搞定<br><br><br><br>效果如图<br>http://www.delphiworld.narod.ru/base/images/tray_hint.jpg<br><br>我找到了happyjoe写的文章了,单元如下<br> <br> Use the AddSysTrayIcon procedure to add icon to notification area <br> (in FormCreate, for example), and use the ShowBalloonTips procedure <br> when ever you want(of cause must after you called AddSysTrayIcon procedure), <br> and finally call DeleteSysTrayIcon procedure to remove icon from <br> notification area after your using. <br> Add propriety code to the callback message handler. <br><br> The new feature require IE5 or later. <br>} <br><br>unit Unit1; <br><br>interface <br><br>uses <br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br><br>{new constant definitions} <br><br>const <br> NIF_INFO = $10; <br> NIF_MESSAGE = 1; <br> NIF_ICON = 2; <br> NOTIFYICON_VERSION = 3; <br> NIF_TIP = 4; <br> NIM_SETVERSION = $00000004; <br> NIM_SETFOCUS = $00000003; <br> NIIF_INFO = $00000001; <br> NIIF_WARNING = $00000002; <br> NIIF_ERROR = $00000003; <br><br> NIN_BALLOONSHOW = WM_USER + 2; <br> NIN_BALLOONHIDE = WM_USER + 3; <br> NIN_BALLOONTIMEOUT = WM_USER + 4; <br> NIN_BALLOONUSERCLICK = WM_USER + 5; <br> NIN_SELECT = WM_USER + 0; <br> NINF_KEY = $1; <br> NIN_KEYSELECT = NIN_SELECT or NINF_KEY; <br> <br> NIN_BALLOONSHOW = WM_USER + 2; <br> NIN_BALLOONHIDE = WM_USER + 3; <br> NIN_BALLOONTIMEOUT = WM_USER + 4; <br> NIN_BALLOONUSERCLICK = WM_USER + 5; <br> NIN_SELECT = WM_USER + 0; <br> NINF_KEY = $1; <br> NIN_KEYSELECT = NIN_SELECT or NINF_KEY; <br> {other constants can be found in vs.net---vc7's dir: PlatformSDK/Include/ShellAPI.h} <br><br> {define the callback message} <br> TRAY_CALLBACK = WM_USER + $7258; <br><br> {new NotifyIconData structure definition} <br>type <br> PNewNotifyIconData = ^TNewNotifyIconData; <br> TDUMMYUNIONNAME = record <br> case Integer of <br> 0: (uTimeout: UINT); <br> 1: (uVersion: UINT); <br> end; <br><br> TNewNotifyIconData = record <br> cbSize: DWORD; <br> Wnd: HWND; <br> uID: UINT; <br> uFlags: UINT; <br> uCallbackMessage: UINT; <br> hIcon: HICON; <br> //Version 5.0 is 128 chars, old ver is 64 chars <br> szTip: array [0..127] of Char; <br> dwState: DWORD; //Version 5.0 <br> dwStateMask: DWORD; //Version 5.0 <br> szInfo: array [0..255] of Char; //Version 5.0 <br> DUMMYUNIONNAME: TDUMMYUNIONNAME; <br> szInfoTitle: array [0..63] of Char; //Version 5.0 <br> dwInfoFlags: DWORD; //Version 5.0 <br> end; <br><br><br>type <br> TForm1 = class(TForm) <br> procedure FormCreate(Sender: TObject); <br> procedure FormDestroy(Sender: TObject); <br> private <br> IconData: TNewNotifyIconData; <br> procedure SysTrayIconMsgHandler(var Msg: TMessage); message TRAY_CALLBACK; <br> procedure AddSysTrayIcon; <br> procedure ShowBalloonTips; <br> procedure DeleteSysTrayIcon; <br> public <br> end; <br><br>var <br> Form1: TForm1; <br><br>implementation <br><br>{$R *.DFM} <br><br>uses <br> ShellAPI; <br><br>procedure TForm1.SysTrayIconMsgHandler(var Msg: TMessage); <br>begin <br> case Msg.lParam of <br> WM_MOUSEMOVE:; <br> WM_LBUTTONDOWN:; <br> WM_LBUTTONUP:; <br> WM_LBUTTONDBLCLK:; <br> WM_RBUTTONDOWN:; <br> WM_RBUTTONUP:; <br> WM_RBUTTONDBLCLK:; <br> //followed by the new messages <br> NIN_BALLOONSHOW: <br> {Sent when the balloon is shown} <br> ShowMessage('NIN_BALLOONSHOW'); <br> NIN_BALLOONHIDE: <br> {Sent when the balloon disappears?Rwhen the icon is deleted, <br> for example. This message is not sent if the balloon is dismissed because of <br> a timeout or mouse click by the user. } <br> ShowMessage('NIN_BALLOONHIDE'); <br> NIN_BALLOONTIMEOUT: <br> {Sent when the balloon is dismissed because of a timeout.} <br> ShowMessage('NIN_BALLOONTIMEOUT'); <br> NIN_BALLOONUSERCLICK: <br> {Sent when the balloon is dismissed because the user clicked the mouse. <br> Note: in XP there's Close button on he balloon tips, when click the button, <br> send NIN_BALLOONTIMEOUT message actually.} <br> ShowMessage('NIN_BALLOONUSERCLICK'); <br> end; <br>end; <br><br> {AddSysTrayIcon procedure add an icon to notification area} <br>procedure TForm1.AddSysTrayIcon; <br>begin <br> IconData.cbSize := SizeOf(IconData); <br> IconData.Wnd := AllocateHWnd(SysTrayIconMsgHandler); <br> {SysTrayIconMsgHandler is then callback message' handler} <br> IconData.uID := 0; <br> IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; <br> IconData.uCallbackMessage := TRAY_CALLBACK; //user defined callback message <br> IconData.hIcon := Application.Icon.Handle; //an Icon's Handle <br> IconData.szTip := 'Please send me email.'; <br> if not Shell_NotifyIcon(NIM_ADD, @IconData) then <br> ShowMessage('add fail'); <br>end; <br><br>{ShowBalloonTips procedure carry out the new feature: Balloon Tips} <br>procedure TForm1.ShowBalloonTips; <br>var <br> TipInfo, TipTitle: string; <br>begin <br> IconData.cbSize := SizeOf(IconData); <br> IconData.uFlags := NIF_INFO; <br> TipInfo := 'Please send me email.'; <br> strPLCopy(IconData.szInfo, TipInfo, SizeOf(IconData.szInfo) - 1); <br> IconData.DUMMYUNIONNAME.uTimeout := 3000; <br> TipTitle := 'Happyjoe@21cn.com'; <br> strPLCopy(IconData.szInfoTitle, TipTitle, SizeOf(IconData.szInfoTitle) - 1); <br> IconData.dwInfoFlags := NIIF_INFO; //NIIF_ERROR; //NIIF_WARNING; <br> Shell_NotifyIcon(NIM_MODIFY, @IconData); <br> {in my testing, the following code has no use} <br> IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION; <br> if not Shell_NotifyIcon(NIM_SETVERSION, @IconData) then <br> ShowMessage('setversion fail'); <br>end; <br><br>{here's the deletion procedure} <br>procedure TForm1.DeleteSysTrayIcon; <br>begin <br> DeallocateHWnd(IconData.Wnd); <br> if not Shell_NotifyIcon(NIM_DELETE, @IconData) then <br> ShowMessage('delete fail'); <br>end; <br><br>procedure TForm1.FormCreate(Sender: TObject); <br>begin <br> AddSysTrayIcon; <br> ShowBalloonTips; <br>end; <br><br>procedure TForm1.FormDestroy(Sender: TObject); <br>begin <br> DeleteSysTrayIcon; <br>end; <br>end.<br><br><br><br>