From: Simon on
Hi,

I am fairly sure there isn't a straight forward way to do it but I
thought I'd ask more knowledgeable people here first.

let say I create a timer for 10 minutes.

::SetTimer( m_hWnd, TIMER_IDENT, 600000, NULL ); // WM_TIMER sent to
CWnd queue

Is it possible to 'pause' the timer or at know how many ms are left
before the WM_TIMER event is fired?

Many thanks

Simon
From: Goran on
On Apr 29, 11:29 am, Simon <b...(a)example.com> wrote:
> Hi,
>
> I am fairly sure there isn't a straight forward way to do it but I
> thought I'd ask more knowledgeable people here first.
>
> let say I create a timer for 10 minutes.
>
> ::SetTimer( m_hWnd, TIMER_IDENT, 600000, NULL ); // WM_TIMER sent to
> CWnd queue
>
> Is it possible to 'pause' the timer or at know how many ms are left
> before the WM_TIMER event is fired?

Pause: no, you can only kill it and set it again.
Remaining time: no way that I know of, so you will need to create a
mechanic of your own. It's not hard (e.g. remember time of last
WM_TIMER and then do long remaining = (lastTick+PERIOD)-Now()).

What are you trying to achieve? (You did not ask a good question,
because you did not say what you are trying to achieve; you said what
you think you should do to achieve it. But normally, you get a better
advice when you say what you are really trying to do; perhaps you
won't even need any of this).

Goran.
From: Hector Santos on
Simon wrote:

> Hi,
>
> I am fairly sure there isn't a straight forward way to do it but I
> thought I'd ask more knowledgeable people here first.
>
> let say I create a timer for 10 minutes.
>
> ::SetTimer( m_hWnd, TIMER_IDENT, 600000, NULL ); // WM_TIMER sent to
> CWnd queue
>
> Is it possible to 'pause' the timer or at know how many ms are left
> before the WM_TIMER event is fired?
>
> Many thanks
>
> Simon


No, but what you can do is have a 1 second or 1 minute timer and
create a counter variables associated with the TIMER_IDENT.

Maybe with a Start Button:

void MyDialog::OnStartButtonClick()
{
m_TimerIdentCount = 10; // 10 mins countdown
m_PauseButton = FALSE;
SetTimer(TIMER_INDENT, 10000, NULL); // 1 min timer
}

then OnTimer has:

void MyDialog::OnTimer(UINT nIdEvent)
{
if (nIdEvent == TIMER_INDENT) {
if (!m_PauseButton) {
m_TimerIdentCount--; // remove 1 minute
if (m_TimerIdentCount <= 0) {
RING_BUZZER()
KillTimer(TIMER_INDENT);
}
}
}
}

Something like that.

--
HLS
From: Tom Serface on
I would just create the time to tick off every second, then you could check
variables like cancel, pause, and you'd always know how much time is left as
it ticks down (you decrement a counter). If the routine is short you
wouldn't see any real difference in your program speed.

Another thing you could do is create a separate thread that keeps track of
this sort of thing and just fires a message off to the appropriate window
when the time comes. You could pause and restart and query that thread for
state, etc.

Tom

"Simon" <bad(a)example.com> wrote in message
news:e9LEA635KHA.1888(a)TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I am fairly sure there isn't a straight forward way to do it but I thought
> I'd ask more knowledgeable people here first.
>
> let say I create a timer for 10 minutes.
>
> ::SetTimer( m_hWnd, TIMER_IDENT, 600000, NULL ); // WM_TIMER sent to CWnd
> queue
>
> Is it possible to 'pause' the timer or at know how many ms are left before
> the WM_TIMER event is fired?
>
> Many thanks
>
> Simon

From: Simon on
> Pause: no, you can only kill it and set it again.
> Remaining time: no way that I know of, so you will need to create a
> mechanic of your own. It's not hard (e.g. remember time of last
> WM_TIMER and then do long remaining = (lastTick+PERIOD)-Now()).

I see what you are saying.
I might do something like that.

>
> What are you trying to achieve?

Yes, I am fairly sure I need it.
We have some use cases to 'pause', (or delay), a timer.
Here is a common example.

We have a server application, when it starts, it checks online for new
transactions every 10 minutes.

During those 10 minutes the user can start a time consuming process,
(printing of reports, connecting to another app, doing a backup), during
the process we do not want to check for transactions.

What I could do is:

OnTimer()
{
if( busy_doing_something_important )
{
// check again in 10 seconds
}
else
{
check_for_transactions()
}
}

Or I could kill the timer and restart it again, but if the user print a
new report every 9:59 minutes then there will be no checks for a very
long time.

On the other hand, if I check for transactions every time we complete a
lengthy transaction then we might end-up checking too often, (during
month end for example we print hundreds of reports).

So on return of a lengthy operation I could check if the timer would
have fired, and in that case check for transactions.

Regards,

Simon
 |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: _in s and _out s ?
Next: MSI Serial Number Validation