|
-
January 13th, 2004, 08:04 PM
#1
How to use Ctime?
Hello,
How are you all? A question, or more like a problem has crept up in my programming as of late. I tried to solve it by myself, but to no avail. It concerns CTime.
There's a part of my program where I require it to execute a certain operation every 100ms, but so far, I could only make a stopwatch type timer. Is there a way where every 100ms, a whole set of subroutine will run?
I ask this becouse I am currently writing a simulation program and I have in mind discrete events happening every 100ms in my simulation.
Please help.
-Andy
-
January 13th, 2004, 08:44 PM
#2
I believe what u need is not CTime class. You need a Timer. Check out SetTimer and KillTimer in MSDN.
-
January 16th, 2004, 01:40 AM
#3
I did that, and i used that. this this the code fragment that i use.
Code:
void ???::OnTimer(UINT nIDEvent)
{...
switch (nIDEvent)
{
case ID_CLOCK_TIMER
break;
case ID_COUNT_TIMER
//**
//the only place (that i know of) that executes once every 100ms
m_iCount++;
break;
}
UpdateData(FALSE);
...
}
...
void ???::OnSimulate()
{
//*
m_iCount=0;
SetTimer(ID_COUNT_TIMER, 100, NULL)
}
is there a way where i can circumvent this method? I meant that the only way i can make sure something happens every 100ms is to put my codes at ** instead of at *. Now, for short codes I wouldn't mind, but the bulk(hundreds of lines) of my codes depend upon it executing every 100ms. is there anyway that i could put my codes in * and still it executes every 100ms??
-
January 16th, 2004, 04:57 AM
#4
The WM_TIMER message is not accurate for what you require; they are processed at low priority, and are often delayed whilst other higher priority messages are processed. I think what you need is MSHTML Timer - look it up in MSDN.
-
January 27th, 2004, 09:25 PM
#5
thank you astanley for your reply. I searched MSDN and I never found the MSHTML Timer you told me. but I did found something about worker thread. But the method described there is a little too crude for my purposes.
now, I believe I have solved my little hiccup; I call the class that I want from the OnTimer class. so far, it works.
just out of curiousity, how do you guys do a simulation software that 'refreshes' the window every few seconds? i mean re-evaluate the variables, re-roll the dice so to speak.
-
January 27th, 2004, 09:37 PM
#6
Originally posted by astanley
The WM_TIMER message [...] processed at low priority, and are often delayed whilst other higher priority messages are processed.
"low priority" and "higher priority" messages??? On Windows?
I always thought there is ONE message queue...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|