Article View: borland.public.cppbuilder.nativeapi
Article #582Re: Multiple Shell_NotifyIcon calls
From: Remy Lebeau (TeamB)
Date: Fri, 29 Feb 2008 18:36
Date: Fri, 29 Feb 2008 18:36
52 lines
3173 bytes
3173 bytes
"Kris" <ks@ks.com> wrote in message
news:47bc8219$1@newsgroups.borland.com...
> I do have another question though. My app is loaded during windows startup
> in the system tray (and does not show its main window). Most of the time
> this works just fine, but occasionally the app gets loaded but no system
> tray icon is created. It's hard to reproduce, but it does happen from time
> to time.
I just noticed this at the bottom of the Shell_NotifyIcon() documentation:
Shell_NotifyIcon Function
http://msdn2.microsoft.com/en-us/library/bb762159.aspx
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.
Gambit
Technical Details
Message-ID:
<47c852f5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47B85E8F.6040508@ks.com> <47bb1415$1@newsgroups.borland.com> <47bc8219$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fd4854ec85a82474 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <47B85E8F.6040508@ks.com> <47bb1415$1@newsgroups.borland.com> <47bc8219$1@newsgroups.borland.com> Subject: Re: Multiple Shell_NotifyIcon calls Date: Fri, 29 Feb 2008 10:36:56 -0800 Lines: 54 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <47c852f5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1204310773 207.178.157.90 (29 Feb 2008 10:46:13 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail