0

I am writing a program in Delphi that displays fresh information in balloons.

Is there a way to determine which balloon I clicked on?

Like this:

sendername := 'Gert'; 

TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!';
TrayIcon1.ShowBalloonHint;

...

sendername := 'Peter'; 

TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!';
TrayIcon1.ShowBalloonHint;

Now I would like to show the related letter in a BalloonClick event, but how can I determine which one was clicked?

2 Answers2

0

Your question seems to imply that multiple balloons can be displayed by a single TTrayIcon component. That is not the case. There is only one balloon, and the text of the balloon will contain whatever you last assigned to BalloonHint.

So in your case, the sendername variable will contain the name that is currently being shown in the balloon.

JP Ritchey
  • 241
  • 1
  • 3
  • Yes, only one is displayed at at a time. But in windows 10, when one balloon is closed, second is shown... and later third is shown if you called TrayIcon1.ShowBalloonHint 3 times. So, how to determine on which balloon I clicked? Bobs, Timmy's or Johns balloon? – LongBeard_Boldy Apr 24 '23 at 16:18
0

There is only one Balloon per TrayIcon, so you can't tell which balloon was clicked.

You can achieve what you're asking by taking advantage of the Tag property that all VCL controls share.

sendername := 'Gert'; 
TrayIcon1.Tag := 1;
TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!';
TrayIcon1.ShowBalloonHint;

sendername := 'Peter'; 
TrayIcon1.Tag := 2;
TrayIcon1.Visible := True;
TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!';
TrayIcon1.ShowBalloonHint;

Now in the TTrayIcon.OnBalloonClick event:

case TrayIcon1.Tag of
  1: // Gert was the sendername
  2: // Peter was the sendername
else
  // Catch any where you forgot to set the tag
  ShowMessage('Unknown sendername. BallooonHint: ' + TrayIcon1.BalloonHint);
end;
TrayIcon1.Tag := 0;  // Reset tag to 0 when finished
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Tag wont help to solve his problem, if his app receives notification that two new messages have been received from 2 different users and ShowBalloonHint is called twice, if you click on the first balloon, tag will be 2, current BalloonHint will be last one. yet he clicked on first balloon and wishes to get first senders ID and show his messages or do something else. – LongBeard_Boldy Apr 24 '23 at 16:31