Select an item from the Python win32 api popup menu

I am using python 2.7 (32-bit) on a 64-bit Windows 7 machine. I am using win32 Api to automate some Windows tasks, I am also new to python and win32 api. I saw similar questions, but not in python, and I was unable to understand the code and, unfortunately, I am new here, so I can not comment and ask questions, because my representative is less than 50, so I had to ask my own question.

Recently, I have been working with the system tray (notification area). I clicked (left or right) on any icon in the tray by name.

Now I need help accessing the context menu items after right clicking.

Therefore, when I make a right click, a popup menu appears . I am trying to get a pen so that I can click on its elements or content, and I get an error message, considering this an invalid menu handle. If I try win32gui.GetSubMenu, it will not work, win32gui.GetMenu will fail, something as simple as win32gui.GetMenuItemCount returns -1, I need help on how to access such a menu, navigate dropped it and clicked the item.

Snippet of code I tried:

# 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 returning the right position of the menu

Any help gratefully thanks you!

+4
source share
1 answer

-, , FindWindow . , , . .

-, FindWindow HWND, HMENU. MN_GETHMENU Windows ( HWND, HMENU).

+3

Source: https://habr.com/ru/post/1526618/


All Articles