python getmenu不到菜单句柄,从弹出菜单win32 api Python中选择项目

博主求助解决在Windows 7 64位系统下,使用Python 2.7(32位)通过Win32API实现右键菜单点击与操作的问题,寻求访问系统托盘菜单并点击上下文菜单项的有效方法,包括菜单句柄获取和处理的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在

Windows 7 64位机器上使用python 2.7(32位).我正在使用win32 Api自动执行一些Windows任务,我也是python和win32 api的新手.我看到了类似的问题,但没有在python中,我无法理解代码,很遗憾我是新来的,所以我不能评论和提问,因为我的代表不到50,所以我不得不提出自己的问题.

最近我一直在使用系统托盘(通知区域).我已经按照名称在托盘中的任何图标上单击(向左或向右).

现在我需要帮助的是右键单击后访问上下文菜单项.

因此,当我执行右键单击时,会出现一个弹出菜单.我试图找到它的句柄,所以我可以点击它的项目或内容,我得到一个错误,说它是一个无效的菜单句柄.如果我尝试win32gui.GetSubMenu它失败,win32gui.GetMenu失败,像win32gui.GetMenuItemCount一样简单返回-1,我需要有关如何访问这样的菜单的帮助,导航扔它并单击一个项目.

我一直在尝试的代码片段:

# retrieves a handle to the notification area toolbar

tb = getNotificationAreaToolbar()

# clicks on an icon in the system tray say I'm right clicking the sound icon

#(in my case AMD HDMI Output)

clickSystemTrayIcon('right','AMD HDMI Output',tb)

#now the context popup menu comes up.

# According to MSDN the class name for such menu is #32768

hPopupmenu = win32gui.FindWindow("#32768","")

# An example of a try to access the menu items

# Getting the count: this is returning -1 saying the handle is not a menu handle

count = win32gui.GetMenuItemCount(hPopupMenu)

#send a command,doesn't do anything

win32gui.PostMessage(tb,win32con.WM_COMMAND,win32gui.GetMenuItemId(hPopupmenu,1),0)

# the thing that makes me sure that I'm getting the right window of the popup is

# win32gui.GetWindowRect(hPopmenu) it's returning the right position of the menu

非常感谢任何帮助,谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值