Shell_NotifyIcon函数调用失败,返回1460错误代码。该怎么办呢

daitounaoshi 2011-06-07 11:50:31
错误描述:由于超时时间已过,该操作返回。

BOOL res;
HICON hicon;
hicon = LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCEA(m_bRun?IDI_STOP:IDI_LISTEN));
//设置托盘数据结构
m_Pallet_Struct.cbSize = sizeof(NOTIFYICONDATA);
m_Pallet_Struct.hWnd = ::AfxGetMainWnd()->m_hWnd;
m_Pallet_Struct.uID = MYICON;
m_Pallet_Struct.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
m_Pallet_Struct.uCallbackMessage = MYWM_NOTIFYICON;
m_Pallet_Struct.hIcon = hicon;
m_Pallet_Struct.uTimeout = 600000;
lstrcpyn(m_Pallet_Struct.szTip,MYTIPX,sizeof(MYTIP));
res = Shell_NotifyIconA(NIM_ADD,&m_Pallet_Struct);
if(!res)
{
DWORD dwCode = GetLastError();
CString sTemp;
sTemp.Format(_T("添加任务栏图标失败,错误代码:%d"),dwCode);
AfxMessageBox(sTemp);
}
if(hicon)
DestroyIcon(hicon);
return res;
...全文
678 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2011-06-07
  • 打赏
  • 举报
回复
uTimeout
Union with uVersion. The timeout value, in milliseconds, for a balloon ToolTip. The system enforces minimum and maximum timeout values. uTimeout values that are too large are set to the maximum value and values that are too small default to the minimum value. The system minimum and maximum timeout values are currently set at 10 seconds and 30 seconds, respectively. See the remarks for further discussion of uTimeout.
「已注销」 2011-06-07
  • 打赏
  • 举报
回复


ERROR_TIMEOUT
1460
This operation returned because the timeout period expired.


-MSDN2005
daitounaoshi 2011-06-07
  • 打赏
  • 举报
回复
解决办法

BOOL res = FALSE;
while(!res)
{
Sleep(1000);
res = Shell_NotifyIcon(NIM_ADD,&m_Pallet_Struct);
}
daitounaoshi 2011-06-07
  • 打赏
  • 举报
回复
Handling Shell_NotifyIcon failure
Shell_NotifyIcon will often fail when called during Windows startup (for instance, if your application is listed in HKLM\Software\Microsoft\Windows\CurrentVersion\Run. This appears to be because the system is busy starting applications. The failure is more common on low-spec computers or computers with some brands of antivirus software installed, which seem to be very intensive at startup.

Unfortunately, you cannot rely on the error code returned by GetLastError. When Shell_NotifyIcon returns false, some of the common errors returned by GetLastError are:

ERROR_FILE_NOT_FOUND (2)
ERROR_TIMEOUT (1460)
ERROR_SUCCESS (0)

The most appropriate response to any error returned by Shell_NotifyIcon is to sleep for a period of time and retry.

An explanation of why the error code may differ has been made by Paul Baker, paraphrased from http://groups.google.com/group/microsoft.public.platformsdk.shell/msg/59235b293cbf5dfa and http://groups.google.com/group/microsoft.public.platformsdk.shell/msg/73973287f15c03fc:

Shell_NotifyIcon actually calls SetLastError(0) initially. After that, basically it uses FindWindow to find the tray notification window. If this fails, it will typically return ERROR_FILE_NOT_FOUND. Otherwise it sends a WM_COPYDATA message to the tray notification window, using SendMessageTimeout with a timeout of only 4 seconds. If that message returns zero, then Shell_NotifyIcon will fail with GetLastError returning zero.

reply to the above...
Applications that want to use the notification APIs that are running before or during explorer startup should listen for the notification message that indicates the taskbar is ready to receive API calls. This is the “TaskbarCreated “ message. This also enables your application to re-register if the explorer is re-started.
This is described in the section titled “Taskbar Creation Notification” on this page:
CODE:// 结构内存用0初使化 - 注意: 一些Windows函数要求这么做,不过我记不得哪些需要,哪些不需要了:) NOTIFYICONDATA niData; ZeroMemory(&niData,sizeof(NOTIFYICONDATA));// 得到Shell32的版本号,并依此设置结构成员cbSize的大小 - 注意:MSDN文档中关于这部分的说明有点模糊不清(见本文后面),所以我并不确定下面的代码是否完全正确 ULONGLONG ullVersion = GetDllVersion(_T("Shell32.dll")); if(ullVersion >= MAKEDLLVERULL(6,0,0,0)) niData.cbSize = sizeof(NOTIFYICONDATA); else if(ullVersion >= MAKEDLLVERULL(5,0,0,0)) niData.cbSize = NOTIFYICONDATA_V2_SIZE; else niData.cbSize = NOTIFYICONDATA_V1_SIZE;// 结构成员uID可以是任何UINT值,这个ID用来标志你的托盘图标,Shell_NotifyIcon函数后面将会用到这个值 niData.uID = MY_TRAY_ICON_ID;// 结构成员uFlags指出哪些结构成员是有效的。此处也可以设置提示窗口的样式,如冒泡提示:NIF_INFO niData.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;// 装载图标。 - 注意:调用完函数Shell_NotifyIcon后应销毁该图标。 niData.hIcon = (HICON)LoadImage( hInstance, MAKEINTRESOURCE(IDI_MY_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);// 设置接收托盘事件消息的窗口句柄。 niData.hWnd = hWnd;// 设置发送消息值。- 注意:消息值的大小应该在WM_APP和0xBFFF之间 niData.uCallbackMessage = MY_TRAY_ICON_MESSAGE;

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧