Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Systray Icon FAQ 3

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I was playing around with System Tray icons and didn't see anything like it in the FAQ, so I put a sample in there. Hope it helps.

faq102-7231

Measurement is not management.
 
FAQ updated with newer code. Functionality changed a bit in the app. Balloon Tooltips and some documentation added.

Measurement is not management.
 
Hi Glenn,

another nice FAQ.
maybe a challenge for you (and our forum members):
create a reusable component from your code?
anyway * for the effort.

I want to add something: When a tray app crashes the tray icon is not deleted.
If you start the tray app a second time, you have 2 tray icons (until you move your mouse over the dead icon)!
I made a small procedure that does exactly this!
It is not 100% failsafe, because people can put their taskbar everywhere with a varying size. Here it is:

Code:
procedure RemoveStaleTrayIcons;

var Hwnd   : THandle;
    X,Y    : Integer;

begin
 try
  // find handle of toolbar
  Hwnd := FindWindow('Shell_TrayWnd', '');
  if Hwnd = 0 then
   Exit;
  Hwnd := FindWindowEx(Hwnd, 0, 'TrayNotifyWnd', nil);
  if Hwnd = 0 then
   Exit;
  Hwnd := FindWindowEx(Hwnd, 0, 'SysPager', nil);
  if Hwnd = 0 then
   Exit;
  Hwnd := FindWindowEx(Hwnd, 0, 'ToolbarWindow32', nil);
  // some mouse_movemessages over each trayicon will trigger their windowproc,
  // if the windowproc does not reply to the callback, the icon is automatically deleted
  if Hwnd <> 0 then
   begin
    Y := 1;
    while Y < 50 do
     begin
      X := 1;
      while X < 400 do
       begin
        Inc(X, 16);
        PostMessage(Hwnd, WM_MOUSEMOVE, 0, Y * $10000 + X);
       end;
      Inc(Y, 16); 
     end;
   end;
 except
  // do nothing, this is best effort
 end;
end;

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
maybe a challenge for you (and our forum members):create a reusable component from your code?

I did have something reusable (to a point) unit not too soon after I made the second post for the project that prompted the sample I posted. Maybe a little fast. As you can probably figure out, I tend to post the interesting things I come across when I'm doing projects for another reason.

Although, it has been a good excuse to work on doing a VCL component and learn how to do that. I still have a few things to figure out for the kind of control this Systray control would be. Mainly how to handle resources the control would use, but also some issues related to the components themselves.

Hopefully all of this will be useful to someone.

Measurement is not management.
 
Got the VCL component done now (I think). It needs a couple of bells and whistles, but hopefully it will work. I would rather not put it into public, though, until I could have someone more knowledgeable about component development tell me if I have all the i's dotted and t's crossed (it is my first one after all).

Measurement is not management.
 
put up a link here, will take a look...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Okay. The source is in there. As well, I rewrote the thing I posted to the FAQ to use the component. It's in there, too. (The icon is pretty bad for right now, but it's there too)

The only idea I got that I might change in implementation is to put the parms for "ShowBalloonTip" as procedure parms instead of published properties. But I thought, too, it might be handy to have them published for design-time for some reason or another.

Please let me know what you think and thanks for the offer.


Measurement is not management.
 
I took down the file associated with that link. Hopefully it was up long enough for whoever that wanted to comment/help to get to see it.

As for using it, I coded up my other project that I had the interest in systray icons for to use the component, and haven't had any real problems with the component itself, so it should be okay. At least from a "correct functionality" standpoint. I did add a couple of features to it that seemed useful for what I was doing with this other app.

The only other real question/problem/issue is something I don't know how to do and haven't found out a good way to do. And that's documentation in the form of help files (HLP or CHM, I suppose either works?). And especially how to link them into your program so F1 brings up the right help item, in both the design time of Delphi (if it's for a component), and when you select an option in your program and click F1.

I suppose the biggest question out of this is getting the help file in the first place, so where do people usually start on that?

Measurement is not management.
 
Delphi 2009 has a built in TTrayIcon, ive been looking at it on my mates pc.

im thinking its time upgrade from my Delphi 7, D2009 looks awesome - but pricey :(

Also has ribbons and other extras
 
Delphi 2009 has a built in TTrayIcon, ive been looking at it on my mates pc.

The one I came up with works on Delphi 3, so I wouldn't use that as a sole excuse to upgrade :) I'll put a "final" version of it on this thread once I figure out the documentation side of things. The context-sensitive help would be nice, but if that doesn't work otherwise, I can just throw it it in a text file.

Measurement is not management.
 
Glenn,
played around with the component. for some reason the ballon tip does not work (on XP SP3). is it working at your side?

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
played around with the component. for some reason the ballon tip does not work (on XP SP3). is it working at your side?

Is this with the demo app I included, or when you use it as a component? It works on my side with both (SP3).

If TipInfo isn't defined, either in the design-time properties or in run-time, the balloon tip will not be functional. I probably should force a default on that field in design-time so it will do something? This would be something that documentation should solve as well.

Hope that helps.

Measurement is not management.
 
New version (and hopefully last, I think I got everything right):


Includes documentation and sample stuff. Also, it has a check on design time if your computer is set like in Microsoft KB #307729.

Hopefully it can be useful.

Measurement is not management.
 
Nice job Glenn! What did you end up using to generate you documentation/help files?

Roo
Delphi Rules!
 
HTML Help Workshop. For the HTML, I realized that most of it would be pretty uniform in the end, so I just used Notepad for that.

Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top