For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > SetTimer with NULL for HWND









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SetTimer with NULL for HWND
Roger Garrett

2006-01-25, 7:23 pm

I'm calling SetTimer (from the platform SDK) as follows:

m_nTimerID = SetTimer(NULL,0 /* EventID, ignored*/,uTimeOut,NULL);

In particular, I'm passing NULL for the HWND (first) parameter. According to
the documentation of SetTimer that means that the second parameter, which is
usually the EventID value, is ignored.

I successfully catch the WM_TIMER messages with my OnMessagePending()
method, using:

BOOL CMyClass::OnMessagePending()
{
MSG msg;
if(::PMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE))
{
// caught the timer message.
}
}

Now, normally with a SetTimer in which you DO pass an HWND, you also pass in
an EventID value, and then when you catch the WM_TIMER method you can examine
the msg.wParam value and compare it to the EventID value to see if it is
indeed the particular timer that was set, meaning that you can potentially
set up multiple timers.

But when you pass in NULL for the HWND parameter to the SetTimer, the
EventID parameter is ignored, so there is no EventID to compare against the
msg.wParam value.

Does this mean that I can only have at most ONE timer? Or is there some
other way to distinguish between timers?

Roger Garrett

Igor Tandetnik

2006-01-25, 7:23 pm

Roger Garrett <RogerGarrett@discussions.microsoft.com> wrote:
> Now, normally with a SetTimer in which you DO pass an HWND, you also
> pass in an EventID value, and then when you catch the WM_TIMER method
> you can examine the msg.wParam value and compare it to the EventID
> value to see if it is indeed the particular timer that was set,
> meaning that you can potentially set up multiple timers.
>
> But when you pass in NULL for the HWND parameter to the SetTimer, the
> EventID parameter is ignored, so there is no EventID to compare
> against the msg.wParam value.


Is too - SetTimer returns it.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Ben Voigt

2006-01-26, 7:08 pm


"Roger Garrett" <RogerGarrett@discussions.microsoft.com> wrote in message
news:3BD97BCA-9815-4D55-A123-8E3417B5FF8F@microsoft.com...
> I'm calling SetTimer (from the platform SDK) as follows:
>
> m_nTimerID = SetTimer(NULL,0 /* EventID, ignored*/,uTimeOut,NULL);
>
> In particular, I'm passing NULL for the HWND (first) parameter. According
> to
> the documentation of SetTimer that means that the second parameter, which
> is
> usually the EventID value, is ignored.


Typically you set the HWND to NULL only if you're planning to use the
TimerProc.

>
> I successfully catch the WM_TIMER messages with my OnMessagePending()
> method, using:
>
> BOOL CMyClass::OnMessagePending()
> {
> MSG msg;
> if(::PMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE))
> {
> // caught the timer message.
> }
> }
>
> Now, normally with a SetTimer in which you DO pass an HWND, you also pass
> in
> an EventID value, and then when you catch the WM_TIMER method you can
> examine
> the msg.wParam value and compare it to the EventID value to see if it is
> indeed the particular timer that was set, meaning that you can potentially
> set up multiple timers.
>
> But when you pass in NULL for the HWND parameter to the SetTimer, the
> EventID parameter is ignored, so there is no EventID to compare against
> the
> msg.wParam value.
>
> Does this mean that I can only have at most ONE timer? Or is there some
> other way to distinguish between timers?
>
> Roger Garrett
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com