catching WM_TIMER message

G

Greg Miller

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!!!!
 
T

Tim Golden

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_hotkeys.html

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.html

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
 
G

Greg Miller

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
 
T

Tim Golden

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?

In short: no need to register (although the WM_TIMER will have to
come from somewhere, ie your process will have to initiated a
SetTimer call. If you aren't familiar with this area, it's worth
your reading up on the way in which Windows message queues and timers
work. There are oodles of examples /tutorials. This is pretty
much the canonical starting point:

http://msdn.microsoft.com/en-us/library/ms644928(VS.85).aspx

but obviously YMMV.

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top