关于调用Shell_NotifyIcon操作托盘图标失败的说明

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:

http://msdn.microsoft.com/en-us/library/cc144179(VS.85).aspx

完整页面见:http://msdn.microsoft.com/zh-cn/library/bb762159%28en-us,VS.85%29.aspx

你可能感兴趣的:(UI界面)