[python-win32] message queue
Tim Roberts
timr at probo.com
Thu Oct 4 20:10:13 CEST 2007
Radu Ciora wrote:
> Hi all,
>
> given this code:
>
> while 1:
> time.sleep(1)
>
> l_hwnd = win32gui.GetForegroundWindow()
> try:
> msg = win32gui.GetMessage(l_hwnd, 0, 0)
> print msg
> except:
> traceback.print_exc()
>
> can anyone tell me what's wrong with it, 'cos it doesn't print anything?
> I'm trying to get into this tiny application message queue and print out the messages that come in to it.
What messages do you expect to get? Are you sending it messages from
somewhere else? How are you doing that?
Are you actually creating any windows? If not, then this will never
work. GetForegroundWindow will return to you the handle of whatever
visible window happens to be frontmost. If you're in a console, it's
the console window. If you're in Pythonwin, it's the Pythonwin window.
In either case, that window does not belong to your thread, so you will
never see any messages destined for that window. Because you supplied a
window handle to GetMessage, it will only pull the messages for that
window handle.
If you want to get ALL messages sent to your thread, do
win32gui.GetMessage( 0, 0, 0 ), but again that begs the question of what
messages you are sending?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list