我看到通知氣球,但未顯示圖標。並且在successfull(返回TRUE)後調用Shell_NotifyIcon後會出現一個窗口錯誤:試圖引用一個不存在的標記。主要問題是爲什麼我沒有看到圖標? Windows 7與最新的更新一起使用。shell_notifyicon:嘗試引用不存在的令牌,但未顯示圖標
下面的代碼片段:
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.
}
}
確保'task_dialog_test.ico'能系統路徑上找到或構建完整的文件名,包括路徑,文件。還要檢查'ExtractIconEx'的返回值是什麼。該文件是否實際包含小(不大)圖標? – Stan
當然,圖標提取後句柄有效。還使用帶圖標ID的LoadImage。錯誤不在那裏。在沒有向數據結構添加圖標時,也會出現@ err,hr指向的錯誤消息。附:也解僱了guid並且只放了data.uID。同樣的結果。 – John
一個由ExtractIconEx返回。 – John