본문 바로가기

프로그래밍/미분류

Shell_NotifyIcon 실패에 대한 대응

반응형

http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159(v=vs.85).aspx


Shell_NotifyIcon 실패에 대한 대응


Handling Shell_NotifyIcon failure


Shell_NotifyIcon 가 윈도우가 시작하며 불리면 종종 실패한다. (예를 들어 응용 프로그램이 HKLM\Software\Microsoft\Windows\CurrentVersion\Run 에 등록되어 있다던가. ) 이유는 시스템이 응용 프로그램들을 시작시키는 데 바쁘기 때문인 것으로 보인다. 이 실패는 낮은 사양의 컴퓨터 또는 시작할 때 부하가 큰 특정 백신 소프트웨어가 설치되어 있는 경우에 더 잘 발생하는 것 같다.


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.


안타깝게도, GetLastError 함수가 리턴하는 에러코드에 너무 의존하면 안 된다. Shell_NotifyIcon 이 실패를 반환하였을 때, GetLastError 다음과 같은 값을 반환하는 것 같다.

ERROR_FILE_NOT_FOUND (2)

ERROR_TIMEOUT (1460)

ERROR_SUCCESS (0)


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)


Shell_NotifyIcon 이 실패했을 때 가장 좋은 대응법은 잠시 쉬었다가 다시 시도하는 것이다.


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


Paul Baker 는 대략 다음과 같이 왜 이런 여러가지 에러코드가 나오는지를 설명했다.


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은 시작하면서 SetLastError(0)을 호출한다. 이후에 FindWindow로 tray notification window 를 찾아본다. 이 시도가 실패하면 보통 ERROR_FILE_NOT_FOUND 가 반환된다. 성공했다면 WM_COPYDATA 메시지를 tray notification window 로 보내는데, 이 때 SendMessageTimeout 을 사용하고 타임아웃 시간은 4초에 불과하다. 이 메시지가 0을 반환하면, Shell_NotifyIcon 은 GetLastError 0 을 반환하며 실패한다.


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...


explorer (탐색기)의 시동하기 전이나 시동중에 실행되는 notification API를 사용하는 응용프로그램은 taskbar가 API 호출을 받을 준비가 되어 있다는 메시지를 기다리고 있어야 한다. 이 메시지는 "TaskbarCreated" 메시지이다. 이것은  explorer 가 재시작 되었을 때에도 트레이를 다시 살려준다. 이에 대한 자세한 내용은 하기 url의 “Taskbar Creation Notification”섹션에 기술되어 있다.

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


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



Thomas Lee ( http://social.msdn.microsoft.com/profile/thomas%20lee/ )

7/18/2009

728x90