我看到通知气球,但没有显示图标。并且在成功(返回 TRUE)调用 Shell_NotifyIcon 后出现 Windows 错误:尝试引用不存在的令牌。主要问题是为什么我看不到图标?Windows 7 与最新更新一起使用。
这是一个代码片段:
namespace tray_tip
{
#define FINAL_INIT( tip, title, ic, icon_id, inst )\
if ( icon )\
{\
static const GUID myGUID = \
{0x23977b55, 0x10e0, 0x4041, {0xb8, 0x62, 0xb1, 0x95, 0x41, 0x96, 0x36, 0x69}};\
data.guidItem = myGUID;\
data.dwInfoFlags |= NIF_ICON;\
ExtractIconEx( _T("task_dialog_test.ico"), 0, NULL, &(data.hIcon), 1 );\
}\
data.dwInfoFlags |= ic;\
_tcscpy_s( data.szInfo, tip );\
_tcscpy_s( data.szInfoTitle, title );
static NOTIFYICONDATA data = {0};
inline void init( HWND const & parent, UINT const & msg_id, UINT const & time_out = 30 )
{
ULONGLONG ullVersion = GetDllVersion( _T( "Shell32.dll" ) );
if ( ullVersion > MAKEDLLVERULL ( 6,0,0,0 ) )
data.cbSize = sizeof ( NOTIFYICONDATA );
else if ( ullVersion == MAKEDLLVERULL( 6,0,0,0 ) )
data.cbSize = sizeof( NOTIFYICONDATA_V3_SIZE );
else if ( ullVersion >= MAKEDLLVERULL( 5,0,0,0 ) )
data.cbSize = NOTIFYICONDATA_V2_SIZE;
else
data.cbSize = NOTIFYICONDATA_V1_SIZE;
data.hWnd = parent;
data.uFlags = NIF_INFO | NIF_MESSAGE;// | NIF_SHOWTIP;
data.uCallbackMessage = msg_id;
data.uTimeout = time_out;
}
inline BOOL show( BOOL show = FALSE, TCHAR tip[256] = _T(""), TCHAR title[64] = _T(""), DWORD const & ic = NIIF_INFO, UINT const & icon = 0, HINSTANCE const & inst_h = NULL )
{
FINAL_INIT( tip, title, ic, icon, inst_h );
return Shell_NotifyIcon( show == TRUE ? NIM_ADD : NIM_DELETE, &data ); // function checks if version can be changed if it was preset.
}
}