//=========================================================================
// 函数名称: SuperSleep
// 函数?明: void 高精度延时,cpu占用低,窗口不卡死,一次最大可延时几年
//=========================================================================
// 参 数: __in int nTime 1000微秒 = 1毫秒 ; 1000毫秒 = 1秒
// 参 数: __in int nSpeed 可空:毫秒 0 毫秒 1 微秒 2 秒 3 分 4 小时 5 天
//=========================================================================
static
void
SuperSleep(__in
int
nTime,__in
int
nSpeed = 0);
//=========================================================================
// 函数名称: ProcessEvent
// 函数?明: void 暂时转让控制权,以便让 Windows 操作系统有机会处理其它的如用户键盘或鼠标输入等事件。
// 直到操作系统处理并发送完程序队列中的所有事件后,命令才会返回。
//=========================================================================
static
void
ProcessEvent();
void
CLibX::System::SuperSleep( __in
int
nTime,__in
int
nSpeed
/*= 0*/
)
{
LARGE_INTEGER lar;
if
(nSpeed == 0) nSpeed = 1;
else
if
(nSpeed == 1) nSpeed = -10;
else
if
(nSpeed == 2) nSpeed = 1000;
else
if
(nSpeed == 3) nSpeed = 1000 * 60;
else
if
(nSpeed == 4) nSpeed = 1000 * 60 * 60;
else
if
(nSpeed == 5) nSpeed = 1000 * 60 * 60 * 24;
lar.QuadPart = -10 * nTime * nSpeed * 1000 ;
HANDLE
hTimer = CreateWaitableTimer(NULL,FALSE,NULL);
SetWaitableTimer(hTimer,&lar,NULL,NULL,NULL,FALSE);
while
(MsgWaitForMultipleObjects(1,&hTimer,FALSE,INFINITE,QS_ALLINPUT) != WAIT_OBJECT_0)
{
CLibX::System::ProcessEvent();
}
CloseHandle(hTimer);
}
void
CLibX::System::ProcessEvent()
{
MSG msg;
while
(PeekMessage(&msg,NULL,NULL,NULL,1) != 0)
{
DispatchMessage(&msg);
TranslateMessage(&msg);
}
}