[python-win32] Simple context-menu question.

Tim Roberts timr at probo.com
Tue Nov 25 18:33:23 CET 2008


Joel Bryan Juliano wrote:
> Based on the context_menu.py example found in
> win32comext\shell\demos\servers\context_menu.py, there is a function
> callback when an item is chosen,
>
> def InvokeCommand(self, ci):
>         mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci
>         win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
>
> My question is how can I get the current names of the "MenuName >
> SubMenuName > SubItemName" when InvokeCommand is called? I apologize
> if this may sound like a dumb question, I'm really new to win32/COM
> programming.. My approach is when I get the names, I can easily call a
> function for them, since the subitems are dynamic and always changing.
>   

You can't get the names.  What you get is the menu identifier (idCmd in
the sample) of the item that was clicked, as the "verb" -- the 3rd
member of the tuple you get in InvokeCommand.  It's up to you to assign
a meaning to that identifier.  The Win32 menu handling doesn't track the
menu "tree".  The tree is only meaningful for display.  It only notifies
you that a menu item was clicked.

I would also caution you that it is not good practice to create deeply
nested context menus.  It makes for a very confusing user experience.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list