Tray Icons with ballooned hints

Hi folks,

Can anyone either point me in the direction of a good free component, or perhaps some source code to allow an application to have a Tray Icon with a ballooned hint?

I want the balloon to appear when the mouse moves over the Tray Icon (similar to the current method with the old style hint).  I also want the hint to disappear after a set time, or if the balloon is clicked.

I'd also like to be able to manually display the balloon if possible.

Cheers!

Stu
LVL 6
Stuart_JohnsonAsked:
Who is Participating?
 
slaviknCommented:
Use:
traTrayIcon.ShowBalloonHint('Caption', 'Text', bitInfo, 15);
in the MouseMove event.
0
 
Stuart_JohnsonAuthor Commented:
Hi Slavikn,

Thanks for that.  It worked great!

If anyone else finds this as a PAQ and wonders how to stop the balloon from flashing, set the OnMouseMove event to nil, then in the OnBalloonHintClick, OnBalloonHideHint and OnBalloonHintTimeout events, set the OnMouseMove event again:

procedure TMainForm.CoolTrayIcon1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  CoolTrayIcon1.OnMouseMove := nil;
  CoolTrayIcon1.ShowBalloonHint('Caption', 'Text', bitInfo, 15);
end;

procedure TMainForm.CoolTrayIcon1BalloonHintHide(Sender: TObject);
begin
  CoolTrayIcon1.OnMouseMove := CoolTrayIcon1MouseMove;
end;

Stu
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
slaviknCommented:
I am glad that I helped!
0
 
Stuart_JohnsonAuthor Commented:
I'd actually looked at that component before, but didn't realise that there was a timeout property for it.  I guess I should read the docos a little closer next time :)

Thanks again!

Stu
0
 
Stuart_JohnsonAuthor Commented:
Are you still about, Slavikn?  I need to ask another question about this tray icon component.

Stu
0
 
slaviknCommented:
Yes Sir!!!    :-)
Feel free to ask.
0
 
Stuart_JohnsonAuthor Commented:
Hi Slavikn,

I've got a slight problem with the tray icon.  It works well, but the problem is, the only way you can make the balloon appear is if it's forced (see code above).  This means there's no time delay (like a hint for instance).  People have complained that if they move their mouse over the icon briefly, the balloon appears - and it's annoying.

Also, under Windows XP, the balloon flashes really quickly if you leave your mouse over the icon.

Do you think you could give me a hand trying to find out how we can get this balloon to work properly?

Thanks for any help.

Stu
0
 
slaviknCommented:
Hi again,

Sorry, must go now. I have an idea how to do it, so I will write to you tomorrow.

   Have a nice day!
      Slavikn.
0
 
SJohnsonCommented:
Hi,

That would be great if you could.  It's frustrating me to no end :)

Cheers!

Stu
0
 
slaviknCommented:
Hi again,

This code seems to be long, but I couldn't make it shorter... Maybe you will find a way. If so, please post it here.

I will post the whole unit. You will see 2 declarations, one function and 2 events.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

unit Unit1;

interface

uses
  Forms, Classes, Windows, CoolTrayIcon;

type
  TForm1 = class(TForm)
    CoolTrayIcon1: TCoolTrayIcon;
    function ShowAfterSecs(TheTrayIcon: TCoolTrayIcon; SecCount: Byte; Par1, Par2: String; Par3: TBalloonHintIcon; Par4: TBalloonHintTimeOut): Boolean;
    procedure CoolTrayIcon1MouseExit(Sender: TObject);
    procedure CoolTrayIcon1MouseEnter(Sender: TObject);
  private
    { Private declarations }
    TempTime: Cardinal;
    ShouldShow: Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.ShowAfterSecs(TheTrayIcon: TCoolTrayIcon; SecCount: Byte; Par1, Par2: String; Par3: TBalloonHintIcon; Par4: TBalloonHintTimeOut): Boolean;
begin
   Result := False;

   If Not ShouldShow Then Begin
      TempTime := 0;
      Exit;
   End;

   If TempTime = 0 Then
      TempTime := GetTickCount;

   If GetTickCount - TempTime > SecCount * 1000 Then
      Begin
         TempTime := 0;
         Result := True;
         ShouldShow := False;
         TheTrayIcon.ShowBalloonHint(Par1, Par2, Par3, Par4);
      End
         Else
      Begin
         Sleep(10);
         Application.ProcessMessages;
         ShowAfterSecs(TheTrayIcon, SecCount, Par1, Par2, Par3, Par4);
      End;
end;

procedure TForm1.CoolTrayIcon1MouseExit(Sender: TObject);
begin
   ShouldShow := False;
end;

procedure TForm1.CoolTrayIcon1MouseEnter(Sender: TObject);
begin
   ShouldShow := True;
   ShowAfterSecs(CoolTrayIcon1, 3, 'Title', 'Text.fertewetrwrtwrt', bitInfo, 10);
end;

end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With regards to your second question, I don't know...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    I hope this helps.
    Slavikn.
0
 
slaviknCommented:
P.S.  Of course, the "WantEnterExitEvents" property of the TrayIcon should be set to TRUE.
0
 
Stuart_JohnsonAuthor Commented:
Hi Slavikn,

That worked really well!  Excellent!  Just give me a day to play with it and make sure it's doing what I want and I'll get back too you.

Thanks for the extremely quick response as well.  I really appreciate it!

Stu
0
 
slaviknCommented:
Hi Stuart Johnson,

I am glad that I helped again.
I go abroad on July 29th, but
I will still answer before 28th.

   Best regards,
   Slavik N.
0
 
Stuart_JohnsonAuthor Commented:
Hi slavikn,

That works a lot better, however there is still a little problem.  If the mouse enters the icon and then leave it, the balloon still pops up after the give time.  I'll try fixing it.  Appart from that it works much better!

Enjoy your holiday!

Stu
0
 
slaviknCommented:
> If the mouse enters the icon and then leave it, the balloon still pops up after the give time.

I had this problem at the beginning, but I fixed it! Are you sure that you enabled the "WantEnterExitEvents"?

This should disable it (it was written above):
procedure TForm1.CoolTrayIcon1MouseExit(Sender: TObject);
begin
  ShouldShow := False;
end;

Before showing the balloon, I check that ShouldShow is set to true, otherwise, I don't show it!

Ok?
0
 
Stuart_JohnsonAuthor Commented:
Hi again,

Yes, the WantEnterExitEvents are definately set to true.

I already have that code set, and it still doesn't work.  If I flash the mouse over the tray icon really quickly, it still shows the balloon.

Here is the weird part.  The MouseExit event is fired AFTER the ShowAfterSecs brings up the balloon.  If I put a breakpoint after the:

  if (GetTickCount - TempTime) > (SecCount * 1000) then

line and another in the MouseExit event, the MouseExit event is fired last everytime.

Could I trouble you to email me a your example?  My email address is gtho1971@hotmail.com.  I don't know why yours is working and mine isn't.

Just as a matter of interest, does Windows actually support these balloons as alternatives to hints, or is what I'm trying to do a "hack" - it was never ment to be that way, therefore we have to force it?

Thanks for the help,


Stu
0
 
slaviknCommented:
> Just as a matter of interest, does Windows actually support these balloons as alternatives to hints, or is what I'm trying to do a "hack" - it was never ment to be that way, therefore we have to force it?

Hmm, I suppose that there is no such a thing as BALLOON hint. But if you try to connect/disconnect your network you will see a balloon. So... I don't know. If there was a normal feature, we would have something like ShowBalloon...

I will send you the files very soon.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.