[python-win32] Using win32 Function GetMenuItemInfo

Weber, Henrik henrik.weber at sdm.de
Fri Aug 20 08:55:18 CEST 2004


> Caution: I'm as newbeeish as they come, read at your
> own risk :-)
>
> I'm trying to use the win32 function GetMenuItemInfo. 
> How do I set up the fourth argument in this function. 
> The documentation says the fourth argument should be
> "A string or buffer in the format of a MENUITEMINFO
> structure."
>
> I don't know what this means.  Here's what I've tried
> to no avail:
> buff = 'MyString'
> win32gui.GetMenuItemInfo(131917, 0, 57600, buff)
>
> This gives me the following error message:
> TypeError: Cannot use string as modifiable buffer

Well, in Python strings are immutable, so you cannot use a string if you want to write something into it. Also, if it wants a MENUITEMINFO structure, you need to supply something that has the size of that structure. You could use a buffer (create with the buffer built-in function) or maybe an array. After calling GetMenuItemInfo you can unpack the result with the struct module.

You can find a description of the structure at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuStructures/MENUITEMINFO.asp

If you are trying to extract a string from a menu item, see what the description says about the dwTypeData member. You'll have to play around with pointers a bit. Maybe the ctypes module can help you out there.

Have fun!
--
Henrik


More information about the Python-win32 mailing list