[python-win32] Finding attached object?

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 5 02:48:20 CET 2009


Mark Hammond wrote:

> Hrm - m_pMenu (and m_pSubMenu) is *supposed* to return a PyCMenu object 
> - what are you seeing?

They're returning a PyCMenu, but not the object that
I have attached to the PyCMenu.

This seems to happen automatically in some other
places, e.g. ui.GetFocus(). If m_pMenu behaved that
way as well, I wouldn't have had a problem.

While on the subject, there's something I'm a bit
confused about. According to the MS docs, when you
destroy an HMENU that has sub-menus attached, the
sub-menus are destroyed as well. This suggests that
the only reasonable way to attach a PyCMenu as a
sub-menu is to Detach its menu handle first.

If that's true, then the PyCMenu object isn't much
use any more, so you might as well throw it away,
and not getting the attached object from m_pMenu
probably isn't so much of a problem.

But what happens if a PyCMenu object returned by
m_pMenu or m_pSubMenu gets deallocated before the
parent menu? It seems as though it will end up
destroying an HMENU that it doesn't really own,
and stuff up the menu that contains it.

On another topic, another thing it would have really
been handy to have access to is the m_bAutoMenuEnable
property of CFrameWnd. PyGUI has its own scheme for
managing menu item enabling, and MFC's one just gets
in the way. If I could turn it off, it would save me
a lot of hassle.

-- 
Greg



More information about the python-win32 mailing list