0
votes

Environment: I'm using Python 2.7 (32-bit) on Windows 7 64-bit. I'm using win32 Api to make a windows automation tool (I know there are some that exist but I'm making my own).

Problem: I'm stuck at the windows System Tray (Notification Area), I get access to the toolbar and I'm able to use TB_GETBUTTON to get the toolbar button info, but I'm having trouble with two things:

1) How do I left/right click an icon in the notification tray? Is there a way to do it by sending a message to the toolbar handle or I need to get the position and send a click. If it's the last case, how do I get the exact position of the icon relative to the screen? (GetRect doesn't help it returns top = 0 and left = 2 which is not relative to the screen).

2) How can I access the hidden icons in the notification are, I can click the button to pop up the menu but I don't know how to access the icons/buttons, like to "right click" an icon and bring up their context menu and go through it.

Any help is greatly appreciated. Thank you!

1
There is no supported mechanism to do this. It is implementation detail that you might be able to use TB_GETBUTTON. There is just no system provided support for this. If you want to see the hidden buttons, fake a click on the << button. But don't expect any support from the system here. It does not want you to do this at all. - David Heffernan
@DavidHeffernan Thanks for the reply! Just what exactly I can and cannot do? Can you be more specific as to what's possible and what's not, because my question had more than one part. - TheCodingGent
None of it is possible through supported APIs. It's all a hack. The best you can manage is faking input. - David Heffernan

1 Answers

0
votes

After my research there's no way to send a click message to a system tray icon, at least not through any API that I tried. The best way to do it and this is the way I'm following is the following:

  1. You Send the message TB_GETBUTTON to the toolbar.
  2. This will retrieve you an "idCommand" for the button you retrieve so you can use a loop to get all the "idCommand", which is found in the TBBUTTON structure.
  3. With the idComman you can send a message to the toolbar button with the toolbar handle to get the dimensions of the icon with the TB_RECT message.
  4. Once you know the dimensions of the button you just need to get the dimensions of the toolbar which is simple because it's just a window you make a cal to GetWindowRect
  5. Last step is now you want to send the click you make a call to win32api.mouse_event with x being: the left bound of the toolbar + half the width of the icon and y being: the top bound of the toolbar + half the height of the icon. (so you're sending the click to the center).