how to tell if notifyicon hooked ok

G

Guest

I have C# code that runs during login (HKEY_LOCAL_MACHINE\\...\\Run...)
This applications main user interface is a notifyicon with a popup menu to
open a larger form.

Orignally I had a problem where the tray icon would only appear
intermitently on reboot. A work around I have place now is to "flash" the
tray icon using the notifyicon.visible property (5 times , 1/2 second not
visible, 1/2 second visible).
This solved the problem of internitent no tray icon, but introduced a
problem of sometimes having multiple tray icons until I hover over some and
the excess ones go away.

I saw an example somewhere that talked about this problem in the context of
shell_notifyIcon dll import and worked around the issue by periodically
retrying the shell_notifyIcon method until it returned "true".

My question is - (in C#, using the notifyIcon forms object) how can I tell
when the notifyicon visible property is successful so I can stop flashing the
icon and hopefully only have one in the tray?


Thanks,
Jim Mead
 
L

Linda Liu [MSFT]

Hi Jim,

Based on my understanding, you have a WinForm application which has a
notify icon displayed in the notification area when it is launched. The
application starts up during login. The problem is that the tray icon does
not always appear when the machine is restarted. If I'm off base, please
feel free to let me know.

When the program is launched properly, the tray icon should be displayed
correctly in the notification area. I performed several tests but couldn't
reproduce the problem on my side.

The following is the steps of my tests.

1.Create a WinForm application project and add a NotifyIcon on the form.

2. In the form's Load event handler, set its WindowState property to
Minimized and ShowInTaskbar property to false and the Visible property of
the NotifyIcon to true.

3. In the DoubleClick event handler of the NotifyIcon, set the WindowState
property of the form to Normal and its ShowInTaskbar property to true and
the Visible property of the NotifyIcon to false.

4. Build the project and add the shortcut to the program to the Start|All
Programs|Startup folder.

When the machine is restarted, the program runs properly with the tray icon
displayed in the notification area. I performed several tests restarting
the machine and the tray icon showed up each time.

You have mentioned that you have found a workaround to your problem, i.e.
'flash' the tray icon using the NotifyIcon's Visible property, and that
this workaround introduced a new problem of sometimes having multiple tray
icons.

I also performed a test 'flashing' the tray icon, but I didn't see the
multiple tray icons.

When your program is launched manually, does it always run properly with
the tray icon displayed? You may also have a try adding a shortcut of the
program to the Start|All Programs|Startup folder and removing registry
entry of the program in the HKEY_LOCAL_MACHINE\\...\\RUN to see if the
problem still exists.

If the problem is still not solved, you may send me your sample project
that could just reproduce the problem. To get my actual email address,
remove 'online' from my displayed email address.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi Jim,

How about the problem now?

If the problem is still not solved and you need our further assistance,
please feel free to let us know.

BTW, I will be on a long vacation from the next Monday to Friday. During my
leave, my team mates will follow up with you and it may not in time. Sorry
for the inconvenience it may bring to you!


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

Thanks four your response Linda,

The problem may be related to how I chose to start the program.
( using HKey LocalMachine Run registry key).

I don't see the same problem when using the Start | All Programs | Startup
folder.

This leads me to a different question -- how can I tell if the program
started from the All Programs Startup folder?

(When using the registry key, I made a registry entry that included the
startup path plus program parameters) --

My goal is that our customer has the choice of running on startup or not,
and that when run normally (not on startup) - the main windows form starts
visible, and when run based on their "run on startup" selection, - the main
window form starts minimized, leaving the tray notifyicon as the primary
interface.

Thanks again,

Jim
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks for your feedback!

Since my colleague Linda is taking vacation next week, I will continue to
work with you. Thanks.
folder?
Can you tell me why you want to tell if your application is started from
"All Programs Startup folder"? Since Linda's and your test both reveal that
placing the application path in "All Programs Startup folder" will resolve
this problem. I think you may implement your application's "run on startup"
function by adding your application shortcut in "All Programs Startup
folder". Does this meet your need? More specific, the
%ALLUSERSPROFILE%\Start Menu\Programs\Startup folder.

Additionally, based on my review to the .Net Winform source code,
NotifyIcon class did not check the return value of shell_notifyIcon API, so
there is no way to check the return value through NotifyIcon class. A
workaround is calling Shell_NotifyIcon API directly through P/invoke
instead of using NotifyIcon.Visible property, so that you can check the
return value explicitly.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top