python getmenu不到菜单句柄,从弹出菜单win32 api Python中选择项目
我在
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
非常感謝任何幫助,謝謝!
總結
以上是生活随笔為你收集整理的python getmenu不到菜单句柄,从弹出菜单win32 api Python中选择项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tp5视图里写原生php,tp5中使用原
- 下一篇: Python学习笔记——glob模块【文