没得高手啊,托盘图标的问题N个,我只有这点分了 (30分)

  • 主题发起人 主题发起人 rEgSpy
  • 开始时间 开始时间
R

rEgSpy

Unregistered / Unconfirmed
GUEST, unregistred user!
托盘图标提示怎么动态改变?<br>win2000以后版本的托盘图标气泡提示,怎么实现?<br>右键菜单弹出了,不点就不消失啊,怎么处理?<br>托盘图标后不能正常关机,怎么处理?<br>&nbsp; sztip 是 array[0..63],用string赋值就不能了,怎么办?<br><br>我只有30分了<br>
 
问题比分多多了,呵呵。我也很关注答案啊!:)
 
没办法,我只有这点分了,要是我有分我分不给吗,我又不会把分拿回去煮着吃<br><br>其实我知道在2000以后要用新的函数,只是我没资料,<br>赋值是我DELPHI功力差的原因,<br>这些问题一个叫happyjoe的高手都解决了的,只是我联系不上他啊,<br>
 
用 StrPCopy()
 
动态改变搞定,谢谢QSmile,其他 问题有办法吗?
 
第二个:托盘气泡提示是指哪种效果。<br>第三个问题我也遇到了<br>第四个问题没有啊<br><br>我也在学习这个托盘图标,但是没你的那种气泡提示。<br>这是我用的在网上查到的资料,没有不能关机的问题<br>不嫌麻烦就你看看<br>unit Unit1; <br><br>interface <br><br>{ 记住在uses部分中包括 ShellAPI} <br>uses <br>Windows, Messages, SysUtils, Classes, <br>Graphics, Controls, Forms, Dialogs, <br>ShellAPI, StdCtrls; <br><br>{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息} <br>{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息} <br>const MY_MESSAGE = WM_USER + 100; <br><br>type <br>TForm1 = class(TForm) <br>procedure FormCreate(Sender: TObject); <br>procedure FormClose(Sender: TObject; var Action: TCloseAction); <br>procedure FormPaint(Sender: TObject); <br>private <br>procedure OnIconNotify(var Message: TMessage); <br>message MY_MESSAGE; <br>public <br>{ Public declarations } <br>end; <br><br>var <br>Form1: TForm1; <br><br>implementation <br><br>{$R *.DFM} <br><br><br>{当小图标捕捉到鼠标事件时进入此过程} <br>{当小图标捕捉到鼠标事件时进入此过程} <br>procedure TForm1.OnIconNotify(var Message: TMessage); <br>const <br>Busy: Boolean = false; <br>begin <br>if not Busy then begin <br>Busy := true; <br>if Message.LParam=WM_LBUTTONDOWN then <br>if Application.MessageBox(&amp;apos;Are you sure&amp;apos;, <br>&amp;apos;Exit&amp;apos;, MB_YESNO)=IDYES then Close; <br>Busy := false; <br>end; <br>end; <br><br>{当主Form建立时通知Windows加入小图标} <br>procedure TForm1.FormCreate(Sender: TObject); <br>var <br>nid: TNotifyIconData; <br>begin <br>nid.cbSize := sizeof(nid); // nid变量的字节数 <br>nid.Wnd := Handle; // 主窗口句柄 <br>nid.uID := -1; // 内部标识,可设为任意数 <br>nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?<br>nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?<br><br>nid.szTip := &amp;apos;This is a test application&amp;apos;; // 提示字符串 <br>nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息 <br>nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?<br><br>if not Shell_NotifyIcon(NIM_ADD, @nid) then begin <br>ShowMessage(&amp;apos;Failed!&amp;apos;); <br>Application.Terminate; <br>end; <br>{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现} <br>SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); <br>end; <br><br>{程序被关闭时通知Windows去掉小图标} <br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); <br>var <br>nid: TNotifyIconData; <br>begin <br>nid.cbSize := sizeof(nid); // nid变量的字节数 <br>nid.cbSize := sizeof(nid); // nid变量的字节数 <br>nid.uID := -1; //内部标识,与加入小图标时的数一致 <br>nid.Wnd := Handle; //主窗口句柄 <br>Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 <br>Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 <br>end; <br><br>{主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏} <br>procedure TForm1.FormPaint(Sender: TObject); <br>begin <br>Hide; <br>end; <br><br>end.
 
&gt;&gt;右键菜单弹出了,不点就不消失啊,怎么处理?<br>把 Popmenu 的 PopupComponent (好象是这样) 设为窗体上一个控件。<br>这样就可以了。<br><br>还有一个情况 窗口弹出后,有时不能最小化,<br>要在窗口显示时用 Restore 方法,<br>以前我写了一个托盘区的程序,反反复复的把我折腾死了。<br>想起来都怕了。<br><br>&gt;&gt;win2000以后版本的托盘图标气泡提示,怎么实现?<br>这不是托盘区自己带的提示框,是用 CreateWindowsEx 创建的一个窗体,<br>用代码显示出来,也是用代码来关闭它的。<br>装了 IE4 就有这个功能。<br>你可以在 MSDN 里显一下 Tooltips 可以找到。<br><br>代码写好了,给我一份可否?<br><br><br><br>
 
楼上的,不是创建的一个窗体<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>&nbsp;<br>&nbsp; Use the AddSysTrayIcon procedure to add icon to notification area <br>&nbsp; (in FormCreate, for example), and use the ShowBalloonTips procedure <br>&nbsp; when ever you want(of cause must after you called AddSysTrayIcon procedure), <br>&nbsp; and finally call DeleteSysTrayIcon procedure to remove icon from <br>&nbsp; notification area after your using. <br>&nbsp; Add propriety code to the callback message handler. <br><br>&nbsp; The new feature require IE5 or later. <br>} <br><br>unit Unit1; <br><br>interface <br><br>uses <br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br><br>{new constant definitions} <br><br>const <br>&nbsp; NIF_INFO = $10; <br>&nbsp; NIF_MESSAGE = 1; <br>&nbsp; NIF_ICON = 2; <br>&nbsp; NOTIFYICON_VERSION = 3; <br>&nbsp; NIF_TIP = 4; <br>&nbsp; NIM_SETVERSION = $00000004; <br>&nbsp; NIM_SETFOCUS = $00000003; <br>&nbsp; NIIF_INFO = $00000001; <br>&nbsp; NIIF_WARNING = $00000002; <br>&nbsp; NIIF_ERROR = $00000003; <br><br>&nbsp; NIN_BALLOONSHOW = WM_USER + 2; <br>&nbsp; NIN_BALLOONHIDE = WM_USER + 3; <br>&nbsp; NIN_BALLOONTIMEOUT = WM_USER + 4; <br>&nbsp; NIN_BALLOONUSERCLICK = WM_USER + 5; <br>&nbsp; NIN_SELECT = WM_USER + 0; <br>&nbsp; NINF_KEY = $1; <br>&nbsp; NIN_KEYSELECT = NIN_SELECT or NINF_KEY; <br>&nbsp; &nbsp;<br>&nbsp; NIN_BALLOONSHOW = WM_USER + 2; <br>&nbsp; NIN_BALLOONHIDE = WM_USER + 3; <br>&nbsp; NIN_BALLOONTIMEOUT = WM_USER + 4; <br>&nbsp; NIN_BALLOONUSERCLICK = WM_USER + 5; <br>&nbsp; NIN_SELECT = WM_USER + 0; <br>&nbsp; NINF_KEY = $1; <br>&nbsp; NIN_KEYSELECT = NIN_SELECT or NINF_KEY; <br>&nbsp; {other constants can be found in vs.net---vc7's dir: PlatformSDK/Include/ShellAPI.h} <br><br>&nbsp; {define the callback message} <br>&nbsp; TRAY_CALLBACK = WM_USER + $7258; <br><br>&nbsp; {new NotifyIconData structure definition} <br>type <br>&nbsp; PNewNotifyIconData = ^TNewNotifyIconData; <br>&nbsp; TDUMMYUNIONNAME &nbsp; &nbsp;= record <br>&nbsp; &nbsp; case Integer of <br>&nbsp; &nbsp; &nbsp; 0: (uTimeout: UINT); <br>&nbsp; &nbsp; &nbsp; 1: (uVersion: UINT); <br>&nbsp; end; <br><br>&nbsp; TNewNotifyIconData = record <br>&nbsp; &nbsp; cbSize: DWORD; <br>&nbsp; &nbsp; Wnd: HWND; <br>&nbsp; &nbsp; uID: UINT; <br>&nbsp; &nbsp; uFlags: UINT; <br>&nbsp; &nbsp; uCallbackMessage: UINT; <br>&nbsp; &nbsp; hIcon: HICON; <br>&nbsp; &nbsp;//Version 5.0 is 128 chars, old ver is 64 chars <br>&nbsp; &nbsp; szTip: array [0..127] of Char; <br>&nbsp; &nbsp; dwState: DWORD; //Version 5.0 <br>&nbsp; &nbsp; dwStateMask: DWORD; //Version 5.0 <br>&nbsp; &nbsp; szInfo: array [0..255] of Char; //Version 5.0 <br>&nbsp; &nbsp; DUMMYUNIONNAME: TDUMMYUNIONNAME; <br>&nbsp; &nbsp; szInfoTitle: array [0..63] of Char; //Version 5.0 <br>&nbsp; &nbsp; dwInfoFlags: DWORD; &nbsp; //Version 5.0 <br>&nbsp; end; <br><br><br>type <br>&nbsp; TForm1 = class(TForm) <br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject); <br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject); <br>&nbsp; private <br>&nbsp; &nbsp; IconData: TNewNotifyIconData; <br>&nbsp; &nbsp; procedure SysTrayIconMsgHandler(var Msg: TMessage); message TRAY_CALLBACK; <br>&nbsp; &nbsp; procedure AddSysTrayIcon; <br>&nbsp; &nbsp; procedure ShowBalloonTips; <br>&nbsp; &nbsp; procedure DeleteSysTrayIcon; <br>&nbsp; public <br>&nbsp; end; <br><br>var <br>&nbsp; Form1: TForm1; <br><br>implementation <br><br>{$R *.DFM} <br><br>uses <br>&nbsp; ShellAPI; <br><br>procedure TForm1.SysTrayIconMsgHandler(var Msg: TMessage); <br>begin <br>&nbsp; case Msg.lParam of <br>&nbsp; &nbsp; WM_MOUSEMOVE:; <br>&nbsp; &nbsp; WM_LBUTTONDOWN:; <br>&nbsp; &nbsp; WM_LBUTTONUP:; <br>&nbsp; &nbsp; WM_LBUTTONDBLCLK:; <br>&nbsp; &nbsp; WM_RBUTTONDOWN:; <br>&nbsp; &nbsp; WM_RBUTTONUP:; <br>&nbsp; &nbsp; WM_RBUTTONDBLCLK:; <br>&nbsp; &nbsp; //followed by the new messages <br>&nbsp; &nbsp; NIN_BALLOONSHOW: <br>&nbsp; &nbsp; {Sent when the balloon is shown} <br>&nbsp; &nbsp; &nbsp; ShowMessage('NIN_BALLOONSHOW'); <br>&nbsp; &nbsp; NIN_BALLOONHIDE: <br>&nbsp; &nbsp; {Sent when the balloon disappears?Rwhen the icon is deleted, <br>&nbsp; &nbsp; for example. This message is not sent if the balloon is dismissed because of <br>&nbsp; &nbsp; a timeout or mouse click by the user. } <br>&nbsp; &nbsp; &nbsp; ShowMessage('NIN_BALLOONHIDE'); <br>&nbsp; &nbsp; NIN_BALLOONTIMEOUT: <br>&nbsp; &nbsp; {Sent when the balloon is dismissed because of a timeout.} <br>&nbsp; &nbsp; &nbsp; ShowMessage('NIN_BALLOONTIMEOUT'); <br>&nbsp; &nbsp; NIN_BALLOONUSERCLICK: <br>&nbsp; &nbsp; {Sent when the balloon is dismissed because the user clicked the mouse. <br>&nbsp; &nbsp; Note: in XP there's Close button on he balloon tips, when click the button, <br>&nbsp; &nbsp; send NIN_BALLOONTIMEOUT message actually.} <br>&nbsp; &nbsp; &nbsp; ShowMessage('NIN_BALLOONUSERCLICK'); <br>&nbsp; end; <br>end; <br><br>&nbsp; {AddSysTrayIcon procedure add an icon to notification area} <br>procedure TForm1.AddSysTrayIcon; <br>begin <br>&nbsp; IconData.cbSize := SizeOf(IconData); <br>&nbsp; IconData.Wnd := AllocateHWnd(SysTrayIconMsgHandler); <br>&nbsp; {SysTrayIconMsgHandler is then callback message' handler} <br>&nbsp; IconData.uID := 0; <br>&nbsp; IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; <br>&nbsp; IconData.uCallbackMessage := TRAY_CALLBACK; &nbsp; //user defined callback message <br>&nbsp; IconData.hIcon := Application.Icon.Handle; &nbsp; &nbsp;//an Icon's Handle <br>&nbsp; IconData.szTip := 'Please send me email.'; <br>&nbsp; if not Shell_NotifyIcon(NIM_ADD, @IconData) then <br>&nbsp; &nbsp; ShowMessage('add fail'); <br>end; <br><br>{ShowBalloonTips procedure carry out the new feature: Balloon Tips} <br>procedure TForm1.ShowBalloonTips; <br>var <br>&nbsp; TipInfo, TipTitle: string; <br>begin <br>&nbsp; IconData.cbSize := SizeOf(IconData); <br>&nbsp; IconData.uFlags := NIF_INFO; <br>&nbsp; TipInfo := 'Please send me email.'; <br>&nbsp; strPLCopy(IconData.szInfo, TipInfo, SizeOf(IconData.szInfo) - 1); <br>&nbsp; IconData.DUMMYUNIONNAME.uTimeout := 3000; <br>&nbsp; TipTitle := 'Happyjoe@21cn.com'; <br>&nbsp; strPLCopy(IconData.szInfoTitle, TipTitle, SizeOf(IconData.szInfoTitle) - 1); <br>&nbsp; IconData.dwInfoFlags := NIIF_INFO; &nbsp; &nbsp; //NIIF_ERROR; &nbsp;//NIIF_WARNING; <br>&nbsp; Shell_NotifyIcon(NIM_MODIFY, @IconData); <br>&nbsp; {in my testing, the following code has no use} <br>&nbsp; IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION; <br>&nbsp; if not Shell_NotifyIcon(NIM_SETVERSION, @IconData) then <br>&nbsp; &nbsp; ShowMessage('setversion fail'); <br>end; <br><br>{here's the deletion procedure} <br>procedure TForm1.DeleteSysTrayIcon; <br>begin <br>&nbsp; DeallocateHWnd(IconData.Wnd); <br>&nbsp; if not Shell_NotifyIcon(NIM_DELETE, @IconData) then <br>&nbsp; &nbsp; ShowMessage('delete fail'); <br>end; <br><br>procedure TForm1.FormCreate(Sender: TObject); <br>begin <br>&nbsp; AddSysTrayIcon; <br>&nbsp; ShowBalloonTips; <br>end; <br><br>procedure TForm1.FormDestroy(Sender: TObject); <br>begin <br>&nbsp; DeleteSysTrayIcon; <br>end; <br>end.<br><br><br><br>
 
&gt;&gt;楼上的,不是创建的一个窗体<br>&gt;&gt;是2000以后的系统就有这个新功能,要VS7中才有资料,<br>我只是不知道用这个方法也可以。<br>因为以前我做的一个就是用 CreateWindowEx 实现的。<br><br>&gt;&gt;右键菜单弹出了,不点就不消失啊,怎么处理?,这个我有理论,就是不能自己做<br>这个什么意思?
 
{当小图标捕捉到鼠标事件时进入此过程}<br>procedure TForm1.OnIconNotify(var Message: TMessage);<br>var<br>&nbsp; TP: TPoint;<br>begin<br>&nbsp; if not Busy then begin<br>&nbsp; &nbsp; Busy := true;<br>&nbsp; &nbsp; if Message.LParam=WM_LBUTTONDOWN then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SetForegroundWindow(self.Handle); &nbsp; &nbsp;//避免菜单无法正常消失!!<br>&nbsp; &nbsp; &nbsp; GetCursorPos(TP);<br>&nbsp; &nbsp; &nbsp; PM1.Popup(TP.X ,TP.Y );<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; if Message.LParam=WM_RBUTTONDOWN then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(self.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; GetCursorPos(TP);<br>&nbsp; &nbsp; &nbsp; &nbsp; PM1.Popup(TP.X ,TP.Y );<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; Busy := not Busy;<br>&nbsp; end;<br>end;
 
to QSmile<br>原理就是在MouseClick时不弹出菜单,改为Post一个自定义的消息,在这个消息响应中弹出菜单<br><br>to skadon<br>谢谢,我试试<br><br>to all<br>谢谢大家啦<br>我记得气泡提示有个关闭按钮的,不知道怎么做<br>
 
to skadon<br>SetForegroundWindow(self.Handle); &nbsp; &nbsp;//避免菜单无法正常消失!!<br><br>OK,谢谢,已搞定
 
接受答案了,只是我分太少,给你们的不多,抱歉啊
 
后退
顶部