本文介绍了单击系统托盘图标Python Win32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:我在Windows 7 64位使用Python 2.7(32位)。我使用win32 Api做一个Windows自动化工具(我知道有一些存在,但我正在做自己的)。

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

问题:我卡在Windows系统托盘(通知区域)工具栏,我可以使用TB_GETBUTTON获取工具栏按钮信息,但我遇到了两个问题:

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)我如何离开/右键单击通知托盘中的图标?有办法做到这一点,发送消息到工具栏的手柄或我需要得到的位置和发送一个点击。如果是最后一种情况,我如何获得图标相对于屏幕的确切位置? (GetRect不帮助它返回top = 0和left = 2这不是相对于屏幕)。

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)如何访问通知,我可以点击按钮弹出菜单,但我不知道如何访问图标/按钮,喜欢右键点击一个图标,并打开他们的上下文菜单,并通过它。

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!

推荐答案

在我的研究后,没有办法发送点击讯息到系统托盘图标,至少不通过任何API我试过。最好的方法,这是我的方式是以下:

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. 您发送消息到工具栏。

  2. 这将为您检索的按钮检索一个idCommand,以便您可以使用循环获取所有的idCommand,它位于结构。

  3. 使用idComman,您可以使用工具栏柄来向工具栏按钮发送消息,以获取图标的尺寸,并使用消息。

  4. 一旦你知道按钮的尺寸只需要得到工具栏的尺寸是简单的,因为它只是一个窗口,你使一个校准

  5. 最后一步是现在要发送点击调用其中x是:工具栏的左边界+图标的宽度的一半,y是:工具栏的上边界+图标的高度的一半。 (因此您将点击发送到中心)。

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

这篇关于单击系统托盘图标Python Win32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 16:05