title: Select item from popup menu win32 api Python
body: <p>I'm using <strong>python 2.7</strong> (32-bit) on a windows 7 64-bit machine. I'm using the <strong>win32 Api</strong> to automate some windows tasks, also I'm new to python and win32 api. I saw similar questions but not in python and I had trouble understanding the code and sadly I'm new on here so I can't comment and ask questions because my rep is under 50, so I had to make my own question.</p>
  
  <p>Lately I've been working with the <em>system tray (notification area)</em>. I've gotten as far as clicking (left or right) on any icon in the tray by name. </p>
  
  <p>Now the thing I need help with is accessing the <strong>context menu items</strong> after a right click. </p>
  
  <p>So when I perform a right click there's a <strong>popup menu</strong> that comes up. I try to get a handle to it so I can click on its items or content and I get an error saying it's an invalid menu handle. If I try win32gui.GetSubMenu it fails, win32gui.GetMenu fails, something as simple as win32gui.GetMenuItemCount is returning -1, I need help on how to access such menu, navigate threw it and click an item.</p>
  
  <p>A snippet of the code I've been trying:</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>Any help is greatly appreciated thank you!</p>