0

I'm trying to figure out a way to add a TButton inside a TTrayIcon Balloon Hint.

Is that possible?

Application description and goal:

Basically my software detects when a USB device is connected to the computer and automatically pops up a balloon hint which notifies the user that a new device has been connected.

What should happen next is to ask the user "Do you want to execute operation A or operation B?", and I'd like to give the user fast access to the options directly inside the ballooon hint.

What I have tried:

Googling a lot, but no success, because there is no info about how to access the balloon hint interface in any way.

I am using Delphi XE2 on Windows 8.

xaid
  • 740
  • 6
  • 18
  • It might be easier making your own balloon window instead. – Jerry Dodge Feb 26 '15 at 04:32
  • @JerryDodge if that is the case, how can I properly replicate Windows balloon window? Also, how can I retrieve the position of the tray icon so that I properly can align the custom balloon windows? Or should I maybe just make my custom ballon window pop up at the bottom right corner with a fixed position? What do you suggest? – xaid Feb 26 '15 at 04:56
  • You'd definitely have to open it in the location of the icon, because the user might move their taskbar to a different part of their screen. As far as making it replicate the original, that's up to your design. There's not necessarily a requirement to follow the standard balloon hint, other than UI standardization. Just many programs do tend to make their own for similar reasons. – Jerry Dodge Feb 26 '15 at 05:01
  • As far as I know the baloon hint does not support adding of custom components to it by default. So you would either have to do some window hacking or making your own implementaion of baloon hint. But why not making life for yourself a bit easer and instead of trying to figure how to implement this simply show a new window with possible choices to the user after he clicks on baloon hint. Yes this will mean that user will have to do one click more but it will greatly ease up the job for you. – SilverWarior Feb 26 '15 at 07:22
  • I'd suggest that hints aren't meant to provide interactive ui via buttons. I'd find a design that fits better with the system. – David Heffernan Feb 26 '15 at 07:44
  • @David, well, sort of. For instance tooltip controls can have a link in the text (and that would still match the OP's requirement). However, I don't think tray icon can do this. – TLama Feb 26 '15 at 08:01
  • Thanks for the info, custom balloon it is then!! – xaid Feb 26 '15 at 16:43

1 Answers1

4

TTrayIcon is a wrapper for Shell_NotifyIcon(), which does not support custom controls in its popup notifications.

You will have to create your own popup window. You can use Shell_NotifyIconGetRect() if you want to position it relative to the tray icon. Just be aware that system tray icons can be hidden by the user, so be prepared that you may have to position your popup window without knowing where the icon is located at times.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thanks, but it says nothing about how to get the tray icon position of my software inside the tray icon area. – xaid Feb 26 '15 at 16:44
  • @AidVllasaliu: That is exactly what `Shell_NotifyIconGetRect()` does. You give it the HWND/ID of the desired tray icon, and it gives you the current screen coordinates of the icon. You can then position your window relative to those coordinates as needed. – Remy Lebeau Feb 26 '15 at 18:25
  • Thanks.I'll use that. – xaid Feb 28 '15 at 00:15