WaitForMultipleObjects()函数
2015-07-23 19:50
781 查看
列表:一个主消息循环,内含MsgWaitForMultipleObjects()
DWORD nWaitCount;
HANDLE hWaitArray[4];
BOOL quit;
int exitCode;
while (!quit)
{
MSG msg;
int rc;
rc = MsgWaitForMultipleObjects(
nWaitCount, hWaitArray, FALSE,
INFINITE, QS_ALLINPUT);
if (rc == WAIT_OBJECT_0 + nWaitCount)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{//get next message in queue
if (msg.message == WM_QUIT)
{
quit = TRUE;
exitCode = msg.wParam;
break;
}///end if
TranslateMessage(&msg);//将虚拟键消息转换为字符消息
DispatchMessage(&msg);//消息传递给操作系统,然后操作系统去调用我们的回调函数
}//end while
}
else if (rc >= WAIT_OBJECT_0 && rc < WAIT_OBJECT_0 + nWaitCount)
{
int nIndex = rc - WAIT_OBJECT_0;
/*we now know that the handle at array position nIndex was signaled .we
would have had to keep track of what those handle mean to decide what to do next*/
}
else if (rc == WAIT_TIMEOUT)
{
}
else if (rc >= WAIT_ABANDONED_0 && rc < WAIT_ABANDONED_0 + nWaitCount)
{
int nIndex = rc - WAIT_ABANDONED_0;
//a thread died that owned a mutex
}
else
{
//something went wrong
}
}
相关文章推荐
- Objective-C JSON字符串解析
- 实习小记-python中可哈希对象是个啥?what is hashable object in python?
- 黑马程序员_Objective-C语言_类和对象
- Win7 _Object_header 中的 TypeIndex
- 浅析Objective-C中的Protocol协议
- Git fatal: failed to read object ..... : Invalid argument
- [Object-C] AutoLaout入门
- Objective-C学习笔记(十三)——函数的声明与调用
- [Objective-C]__bridge,__bridge_retained和__bridge_transfer的意思,区别与使用
- QObject怎样把ppt嵌入qt widget里显示,并控制自动播放
- Object类的重要方法
- Django Related objects
- Objective-C学习笔记(十二)——switch多分支语句的使用
- TaskQueS.c---分配工作并以WaitForSingleObject()等待之
- iOS Object-C 基础 UIlabel
- Objective-C学习笔记(十一)——break和continue的使用方法
- Error creating object Please verify that the Microsoft Data Access Components 2.1 (or later) have be
- Objective-C学习笔记(十)——循环语句for和do-while的使用
- Objective-C学习笔记(九)——循环语句while的使用方法
- Objective-C学习之旅 第三篇