江湖告急:明天就要交了,各位帮帮忙!一个简单的问题!!!!!!!!在线等待!!!!!!!

linghushaonian 2002-06-27 05:30:04
我有一个控制台程序,主函数中有:
while(1)
{
cout << " CMD>> " ;
cin >> command;
switch ( command[0] ){
case 'x' :...
case '':..
}
}
现在还差一个功能:当每个整点时需执行一个函数my_time(),请问怎么实现?2k下?
...全文
82 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
linghushaonian 2002-06-27
  • 打赏
  • 举报
回复
各位帮帮忙啊!!!!!!!!!!
linghushaonian 2002-06-27
  • 打赏
  • 举报
回复
谢谢各位的关注,关于SetWaitableTimer我已解决了,但目前的问题是我需要实现的那个功能仍然没有实现,因为我用的是单线程,所以SetWaitableTimer函数没用,请各位帮帮忙?是只能用中断才能实现吗?可在2k下怎么实现呢?
linghushaonian 2002-06-27
  • 打赏
  • 举报
回复
to deadhorse(死马):我程序中主函数如上,并没有使用消息,多线程。请继续关注,谢谢
to Nizvoo(瓦匠泥 钟松风 100%投入中):你贴得资料我也在msdn上查到一些,但是我即使照上面那个例子,也出现如上g:\MyProjects\C++work\monitor\main.CPP(449): error C2065: “CreateWaitableTimer” : 未声明的标识符
g:\MyProjects\C++work\monitor\main.CPP(459): error C2065: “SetWaitableTimer” : 未声明的标识符
的错误,不只怎么解决?我已包含windows.h文件,谢谢
Nizvoo 2002-06-27
  • 打赏
  • 举报
回复
SetWaitableTimer
The SetWaitableTimer function activates the specified waitable timer. When the due time arrives, the timer is signaled and the thread that set the timer calls the optional completion routine.

BOOL SetWaitableTimer(
HANDLE hTimer, // handle to timer
const LARGE_INTEGER *pDueTime, // timer due time
LONG lPeriod, // timer interval
PTIMERAPCROUTINE pfnCompletionRoutine, // completion routine
LPVOID lpArgToCompletionRoutine, // completion routine parameter
BOOL fResume // resume state
);
Parameters
hTimer
[in] Handle to the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle.
pDueTime
[in] Specifies when the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by the FILETIME structure. Positive values indicate absolute time. Be sure to use a UTC-based absolute time, as the system uses UTC-based time internally. Negative values indicate relative time. The actual timer accuracy depends on the capability of your hardware. For more information about UTC-based time, see System Time.
lPeriod
[in] Specifies the period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once. If lPeriod is greater than zero, the timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the CancelWaitableTimer function or reset using SetWaitableTimer. If lPeriod is less than zero, the function fails.
pfnCompletionRoutine
[in] Pointer to an optional completion routine. The completion routine is application-defined function of type PTIMERAPCROUTINE to be executed when the timer is signaled. For more information on the timer callback function, see TimerAPCProc.
lpArgToCompletionRoutine
[in] Pointer to the structure that is passed to the optional completion routine.
fResume
[in] Specifies whether to restore a system in suspended power conservation mode when the timer state is set to signaled. If fResume is TRUE on a platform that does not support a restore, the call will succeed, but GetLastError returns ERROR_NOT_SUPPORTED.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Timers are initially inactive. To activate a timer, call SetWaitableTimer. If the timer is already active when you call SetWaitableTimer, the timer is stopped, then it is reactivated. Stopping the timer in this manner does not set the timer state to signaled, so threads blocked in a wait operation on the timer remain blocked.

When the specified due time arrives, the timer becomes inactive and the APC is queued to the thread that set the timer. The state of the timer is set to signaled, the timer is reactivated using the specified period, and the thread that set the timer calls the completion routine when it enters an alertable wait state. For more information, see QueueUserAPC.

If the thread that set the timer exits before the timer elapses, the timer is cancelled. If you call SetWaitableTimer on a timer that has been set by another thread and that thread is not in an alertable state, the completion routine is cancelled.

When a manual-reset timer is set to the signaled state, it remains in this state until SetWaitableTimer is called to reset the timer. As a result, a periodic manual-reset timer is set to the signaled state when the initial due time arrives and remains signaled until it is reset. When a synchronization timer is set to the signaled state, it remains in this state until a thread completes a wait operation on the timer object.

Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

See Also
Synchronization Overview, Synchronization Functions, CancelWaitableTimer, CreateWaitableTimer, FILETIME, OpenWaitableTimer, TimerAPCProc
deadhorse 2002-06-27
  • 打赏
  • 举报
回复
SetTimer()不就好了吗?然后处理wm_timer消息。
不会说你没有创建消息循环吧?
linghushaonian 2002-06-27
  • 打赏
  • 举报
回复
我试了,但提示g:\MyProjects\C++work\monitor\main.CPP(449): error C2065: “CreateWaitableTimer” : 未声明的标识符
g:\MyProjects\C++work\monitor\main.CPP(459): error C2065: “SetWaitableTimer” : 未声明的标识符
是不是需要加什么条件编译?谢谢指教
andy_lau 2002-06-27
  • 打赏
  • 举报
回复
Api函数SetWaitableTimer
linghushaonian 2002-06-27
  • 打赏
  • 举报
回复
Thank you!我先试试看
duiduiblues 2002-06-27
  • 打赏
  • 举报
回复
查一下SetWaitableTimer的用法,让你设置一个内核级别的Timer,不需要窗口

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧