[pythonwin] popup menu problems (was: [Pythonwin] Help needed creating a Window)

Dave Kirby dave_kirby at eur.3com.com
Tue Jun 22 07:25:54 EDT 1999


On Mon, 14 Jun 1999 15:53:03 GMT, I wrote:

>Thanks to Mark Hammond's help I now have an app that displays an icon
>in the system tray which I can process messages from. However when I
>try to create a popup menu menu for it nothing happens. The call to
>PyCMenu.TrackPopupMenu doesnt display anything and never returns.  I
>have tried both using it to send a notify message to the window and
>returning a command, but it didnt make any difference. I am unsure
>whether it is a failure of my understanding of the way Windows does
>these things, a bug in my code, or a problem with pythonwin. 
> [ example code snipped ]

I have discovered what the problem was - the line 
            self.cMenu.TrackPopupMenu( pos, owner=self.cWnd )
was failing with an exception since it didnt like the use of named
parameters, but the exception was geting discarded somewhere along the
way. I only found it when I enclosed the line in a try/except clause.
I *think* the exception is getting caught & thrown away somewhere in
the pythonwin code since I didnt have any try clauses in my code at
that point.

I now have the popup menu working, except for one small problem. When
I run it using python(w).exe the menu appears in the correct place and
the user can select a menu item ok, but clicking outside of the menu
doesn't dismiss it. There is no way to get rid of the menu without
selecting a menu item.  When I run it from within Pythonwin.exe it
works fine[1], so I presume that the problem is that there is no top
level window to process the WM_CANCELMODE message.  Is there a way to
register my icon window to handle this message, or do I need to go the
full PythonWin route? My app doesnt use the doc/view architecture so I
want to avoid unnecessary complication if possible. From looking at
the source for win32ui.dll the menu routines call the C API directly,
bypassing MFC, so I would have thought it was possible. 

	Dave K


[1] well, almost - further experimentation shows that it only closes
the menu if I click within the Pythonwin window, rather than anywhere
on the screen. 





More information about the Python-list mailing list