Click System Tray Icon Python Win32

本小妞迷上赌 提交于 2019-12-25 04:02:27

问题


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:


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).


来源:https://stackoverflow.com/questions/21706428/click-system-tray-icon-python-win32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!