catching WM_TIMER message

Greg Miller et1ssgmiller at gmail.com
Mon Sep 20 18:41:33 CEST 2010


On Sep 20, 11:30 am, Tim Golden <m... at timgolden.me.uk> wrote:
> On 20/09/2010 16:15, Greg Miller wrote:
>
> > I'm trying to get the following code converted to Python.......and am
> > stuck
>
> > if(GetMessage(&msg.NULL,NULL,NULL))
> > {
> >       if(msg.message == WM_TIMER)
> >       {
> >            TranslateMEssage(&msg);
> >            DispatchMessage(&msg);
> >       }
> > }
>
> > I think GetMessage is a canned C or C++ function, and I'm not sure how
> > to catch a message from WM_TIMER.  Anyone who could help me get this
> > loop converted to Python I would really appreciate it!!!!
>
> Goodness. You're going in at the deep end, slightly.
>
> What you're seeing there is a typical part of the standard
> Windows message loop which retrieves messages from the
> message queue of a Window (or thread) and then dispatches
> as your code does above. You *can* do this in Python, either
> using core Python only and making use of the ctypes module,
> or by employing the pywin32 packages which wrap the functions
> above.
>
> There's a thread-based example here which uses ctypes:
>
> http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkey...
>
> It should be readily adaptable to a WM_TIMER situation.
>
> Or you can see a (more complex) window-based example here which
> uses the pywin32 package:
>
>    http://timgolden.me.uk/python/win32_how_do_i/detect-device-insertion....
>
> If all you needed was the simplest code to catch a WM_TIMER
> message then the earlier example is probably a better fit.
> If this is part of a wider setup involving windows and other
> messages then you'll need (something like) the latter.
>
> TJG

Thank you for the assist!  Quick question though, using the first
example is there any need to register for WM_TIMER, ( instead of
registering for WM_HOTKEY ), or is extracting the "home grown Windows
message loop" enough and just run with that?

et1ssgmiller



More information about the Python-list mailing list