Placing an icon in the system tray

P

Patrick Dugan

Are there any source code examples of how to place an icon in the system
tray using vb.net and a smart device? I have found examples for vb.net but
they do not work for smart device (PPC) Can anyone point me to a specific
example of placing an icon in the system tray of a PPC suing VB.NET?
 
P

Peter Foot [MVP]

P

Patrick Dugan

Yes I intend to place the icon at the bottom on the today screen.
Unfortunately all the examples I'm seeing are
written for C and not VB and I'm having a time trying to convert the C
examples to VB.
 
P

Patrick Dugan

Well your example doesn't seem to work. It required an additional


IconMessageWindow wnd;

or it would not recognize the WND on the next line:

wnd = new IconMessageWindow();


After adding the statement the program will run but will not display the
icon on a PPC with 2003. The invisible icon can be clicked
on but it does not display the icon.
 
P

Paul G. Tobey [eMVP]

Hmmm. Ran it just as it is two minutes before zipping it up so I know that
it works as a whole.

My form has a 'wnd' member as you'll see if you take a look at line 52 of
form1.cs.

On the icon thing, did you make sure that the application icon (project
settings), was set to the icon file? I suppose that it might also be
necessary to have a 32x32 version of the icon, which it's not on my devices
(don't have a PPC).

Paul T.
 
P

Patrick Dugan

I tried the example at home and it didn't have the problem with the wnd so
I'm not sure what I did before to cause that. The icon still will not
appear at all. The area where the icon should be does react to mouse clicks
it just doesn't have an image. I tried 32x32 but it made no difference. Of
course I'm not a C programmer so even if I get it to function I get
translate it to VB which I need it in. I do appreciate your help though.
 
P

Patrick Dugan

I searched your site for "system tray" "tray" "icon" but never found
anything that would show an example.

Programming for something this simple (just an icon in the tray) shouldn't
be this difficult. *wah* :(
 
P

Peter Foot [MVP]

The WinAPI library contains several helper functions in the Core class -
RegisterTrayIcon and UnregisterTrayIcon along with two events. We have a
more intuitive NotfyIcon in the works that will be available in the not too
far distant future.

Peter
 
P

Paul G. Tobey [eMVP]

You don't need to have every single thing in your project be in C#. People
are making a lot of extra work for themselves by trying to do that. You
need the *client* portion of the code to be in VB.NET, maybe (although I
think it's crazy for anyone to assume that they can be 'just' a VB.NET
programmer any more; it's not that different from C#, anyway), but the
NotifyIcon namespace, for example, doesn't need to be translated to VB.NET
to work in a VB.NET application.

If the icons are not working, as I mentioned, verify that the project
settings have the icon set as the application icon. Further, let us know
what the display characteristics of your device are. If it's a B&W device,
it's likely that a 16-color icon isn't going to work and you may need to
create a new device image for the icon which is 2-color, instead. I don't
have any 16-bit color devices around here, but maybe there's an issue with
16-color images on those devices for the tray or something, too.

Paul T.
 
C

Chris Dunaway

On the icon thing, did you make sure that the application icon (project
settings), was set to the icon file? I suppose that it might also be
necessary to have a 32x32 version of the icon, which it's not on my devices
(don't have a PPC).

I notice you use the following lines to load the icon:

// Load icon.
string szPath =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;

NotifyIcon.NotifyIcon.ExtractIconEx(szPath, 0, 0, ref icon, 1);


I tried this approach:

oIcon = new
Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("NotifyIcon.test.ico"),32,32);
hIcon = Icon.GetHicnFromIcon(oIcon);

The .ico file is included in the project and its build action is set to
"Embedded Resource".

The GetHicnFromIcon method is not documented. I found it in the object
browser. It seems to get a valid IntPtr to the icon.

But when run, the icon is not displayed. I can click the area where the
icon would normally appear and it reacts to the click, but no icon is
visible. Any ideas?
 
P

Paul G. Tobey [eMVP]

Peter is looking at that for the OpenNetCF stuff. He says that the HIcon
returns doesn't appear valid, so maybe there's a reason the method is
undocumented. It would be nice if someone from MS could give us a way to
get a valid handle to an icon from the .NET Icon class...

Paul T.

Chris Dunaway said:
On the icon thing, did you make sure that the application icon (project
settings), was set to the icon file? I suppose that it might also be
necessary to have a 32x32 version of the icon, which it's not on my devices
(don't have a PPC).

I notice you use the following lines to load the icon:

// Load icon.
string szPath =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;

NotifyIcon.NotifyIcon.ExtractIconEx(szPath, 0, 0, ref icon, 1);


I tried this approach:

oIcon = new
Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("NotifyIcon.t
est.ico"),32,32);
hIcon = Icon.GetHicnFromIcon(oIcon);

The .ico file is included in the project and its build action is set to
"Embedded Resource".

The GetHicnFromIcon method is not documented. I found it in the object
browser. It seems to get a valid IntPtr to the icon.

But when run, the icon is not displayed. I can click the area where the
icon would normally appear and it reacts to the click, but no icon is
visible. Any ideas?


--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
 
C

Chris Dunaway

undocumented. It would be nice if someone from MS could give us a way to
get a valid handle to an icon from the .NET Icon class...

The Handle property of the Icon class works in desktop windows forms apps,
but for some reason (probably a sadistic one at that), they decided to tie
the hands of CF developers.
 
P

Peter Foot [MVP]

I'm pretty sure these decisions aren't made lightly - they've had to really
squeeze the framework to fit on smart devices so something has to give.
Hopefully I'll have some code available soon which will get a valid handle
from an Icon object.

Peter
 

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