Archived

This topic is now archived and is closed to further replies.

GetTickCount()

This topic is 5500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello- I am trying to get a simple time count for my little program. I have created a class which handles this called CTime. Below is the section of code which is giving me troubles.
  
int CTime::Update()
{
	if(bSet)
	{
		DWORD ElapsedTime = 0, CurrentTime = 0;

		CurrentTime = GetTickCount();
                //this is where it gets crazy

		ElapsedTime = (BeginningTime - CurrentTime);

		if(ElapsedTime < 1000)
		{
			FrameRate++;
			return 0;
		}
		else
		{
			int FrameRateToken = FrameRate;
			FrameRate = 0;
			bSet = false;
			return FrameRateToken;
		}
	}
	else
	{
		BeginningTime = GetTickCount();
		bSet = true;
		return 0;
	}	
}
  
for some reason, it isn''t giving me the difference of the two vaiables. WHat have i done wrong? I already see a logic error, but that is easily fixed. i just want to know why my math isn''t working.

Share this post


Link to post
Share on other sites
This is probably the logic error you were talking about, but try changing the line to this:

  
ElapsedTime = (CurrentTime - BeginningTime);


Alexander "DmGoober" Jhin
alexjh@online.microsoft.com
[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]

Share this post


Link to post
Share on other sites
Doesn''t GetTickCount() return time in milliseconds? so u should multiple the return time by 1000 to get time in seconds. Just my 2 cents.


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
It actually doesn''t matter if it wraps around when you are taking the difference. With the underflow, the huge negative becomes a relatively small positive, still the difference you want. If you are just looking for the time to be bigger than an old time (don''t really know why you would), then you have to check for wrap, otherwise you''re fine.

Karg

Share this post


Link to post
Share on other sites