[英]C++ noob: I need help creating a simple timer function
I'm a C++ beginner. 我是C ++初学者。 I'm searching for a way to may a simple timer function for a very simple console game (class assignment).
我正在寻找一种可以为非常简单的控制台游戏(类分配)提供简单计时器功能的方法。 Hopefully a preexisting function from a common library?
希望来自公共库的预先存在的功能? Please keep it simple since I am new.
由于我是新来的,请保持简单。 Thanks.
谢谢。 Sorry if I'm not wording this correctly.
抱歉,如果我的措词不正确。 Brand new to this forum as well!
也是这个论坛的新手!
http://en.cppreference.com/w/cpp/chrono/c/time http://en.cppreference.com/w/cpp/chrono/c/time
http://www.cplusplus.com/reference/ctime/ http://www.cplusplus.com/reference/ctime/
It's not that different from any other loop or iteration, simply use the given values/constant as your condition. 它与任何其他循环或迭代没有什么不同,只需使用给定的值/常量作为条件即可。
Assuming you are using plain C++ in Win32 there is a function SetTimer()
from the Win32 API
that goes like this 假设您在Win32中使用纯C ++,则
Win32 API
中有一个函数SetTimer()
如下所示
UINT myTimer = SetTimer ( hwnd, ID_60SECONDS, 60 * 1000, NULL );
You will then need to add a case
statement to your WndProc
to handle the elapsed timer 然后,您需要在
WndProc
添加一个case
语句来处理经过的计时器
case WM_TIMER:
switch (wParam)
{
case ID_60SECONDS:
// We processed it, so return 0
return 0;
}
break;
Unfortunately, this involves dealing with Win32 which is no that easy but once you got the hang it is very obvious. 不幸的是,这涉及到处理Win32的过程并非易事,但是一旦遇到问题,这是非常明显的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.