如何托盘图标自动弹出提示信息?(不是将鼠标放到图标上)(50分)

  • 主题发起人 主题发起人 wgzhou
  • 开始时间 开始时间
W

wgzhou

Unregistered / Unconfirmed
GUEST, unregistred user!
比如:托盘上有两个小电脑的图标表示网线是否插好,当插拔网线的时候,图标处会自动弹出相应的提示信息。
 
使用CoolTrayIcon控件,里面有一个ShowBalloonHint可以实现你的功能。
 
我的程序里没有用控件,如果不用控件该怎么写?
 
你看一下下面的代码,其实就是使用Shell_NotifyIcon进行的。<br><br>function TCoolTrayIcon.ShowBalloonHint(Title: String; Text: String;<br>&nbsp; IconType: TBalloonHintIcon; TimeoutSecs: TBalloonHintTimeOut): Boolean;<br>// Show balloon hint. Return false if error.<br>const<br>&nbsp; aBalloonIconTypes: array[TBalloonHintIcon] of Byte =<br>&nbsp; &nbsp; (_NIIF_NONE, _NIIF_INFO, _NIIF_WARNING, _NIIF_ERROR);<br>begin<br>&nbsp; // Remove old balloon hint<br>&nbsp; HideBalloonHint;<br>&nbsp; // Display new balloon hint<br>&nbsp; with IconData do<br>&nbsp; begin<br>&nbsp; &nbsp; uFlags := uFlags or _NIF_INFO;<br>&nbsp; &nbsp; StrLCopy(szInfo, PChar(Text), SizeOf(szInfo)-1);<br>&nbsp; &nbsp; StrLCopy(szInfoTitle, PChar(Title), SizeOf(szInfoTitle)-1);<br>&nbsp; &nbsp; TimeoutOrVersion.uTimeout := TimeoutSecs * 1000;<br>&nbsp; &nbsp; dwInfoFlags := aBalloonIconTypes[IconType];<br>&nbsp; end;<br>&nbsp; Result := ModifyIcon;<br>&nbsp; { Remove _NIF_INFO before next call to ModifyIcon (or the balloon hint<br>&nbsp; &nbsp; will redisplay itself) }<br>&nbsp; with IconData do<br>&nbsp; &nbsp; uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP;<br>end;<br><br>function TCoolTrayIcon.ModifyIcon: Boolean;<br>// Change icon or tooltip if icon already placed<br>begin<br>&nbsp; Result := False;<br>&nbsp; if InitIcon then<br>&nbsp; &nbsp; Result := Shell_NotifyIcon(NIM_MODIFY, @IconData);<br>end;<br>
 
还有这个声明。<br>&nbsp;TNotifyIconDataEx = record<br>&nbsp; &nbsp; cbSize: DWORD;<br>&nbsp; &nbsp; hWnd: HWND;<br>&nbsp; &nbsp; uID: UINT;<br>&nbsp; &nbsp; uFlags: UINT;<br>&nbsp; &nbsp; uCallbackMessage: UINT;<br>&nbsp; &nbsp; hIcon: HICON;<br>&nbsp; &nbsp; szTip: array[0..127] of AnsiChar; &nbsp;// Previously 64 chars, now 128<br>&nbsp; &nbsp; dwState: DWORD;<br>&nbsp; &nbsp; dwStateMask: DWORD;<br>&nbsp; &nbsp; szInfo: array[0..255] of AnsiChar;<br>&nbsp; &nbsp; TimeoutOrVersion: TTimeoutOrVersion;<br>&nbsp; &nbsp; szInfoTitle: array[0..63] of AnsiChar;<br>&nbsp; &nbsp; dwInfoFlags: DWORD;<br>{$IFDEF _WIN32_IE_600}<br>&nbsp; &nbsp; guidItem: TGUID; &nbsp;// Reserved for WinXP; define _WIN32_IE_600 if needed<br>{$ENDIF}<br>&nbsp; end;<br><br>var<br>&nbsp; &nbsp; IconData: TNotifyIconDataEx; &nbsp; &nbsp; &nbsp; // Data of the tray icon wnd.<br>
 
不过强烈建议你使用CoolTrayIcon,因为他为我们考虑的很全了,且算是比较“绿色”的,删除控件对程序没有什么影响,且CoolTrayIcon本身只有三个pas文件。<br><br>他可以实现弹出菜单、Hint、BalloonHint、还可以在系统Crash(Explorer重启)的时候重建任务栏图标。
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部