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_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
--
http://mail.python.org/mailman/listinfo/python-list