简体   繁体   English

注册以在MFC中发出Win32事件时接收Windows消息

[英]Register to receive windows messages when an Win32 event is signaled in MFC

I have a simple MFC dialog app. 我有一个简单的MFC对话框应用程序。 I would like to do some overlapped I/O. 我想做一些重叠的I / O。 Waiting for the overlapped event handle in a separate thread is a pain. 在单独的线程中等待重叠的事件句柄很痛苦。 I'm wondering if there is a function call to register a windows message to a waitable handle? 我想知道是否存在将Windows消息注册到等待句柄的函数调用? Much like how WSAAsyncSelect works, but without the socket and just a generic Win32 waitable handle (event, mutex, pipe, etc). 与WSAAsyncSelect的工作原理非常相似,但没有套接字,而只有通用的Win32等待句柄(事件,互斥量,管道等)。

My environment: Windows XP, Visual Studio 2010 我的环境:Windows XP,Visual Studio 2010

Thanks! 谢谢!

Given your constraints, I'd use RegisterWaitForSingleObject() to register a callback routine that'll be invoked when the object you waiting on is signaled. 考虑到您的限制,我将使用RegisterWaitForSingleObject()注册一个回调例程,该信号将在发出等待对象的信号时被调用。

The callback function is simple - it merely needs to Post a user defined message to the interested window indicating that the event is signaled. 回调函数很简单-它仅仅需要发布一个用户定义的消息表明该事件标志着感兴趣的窗口。

That said, if you're using ReadFileEx() , WriteFileEx() , or other I/O function that supports a completion callback, you can use that callback to achieve similar functionality. 就是说,如果您使用ReadFileEx()WriteFileEx()或其他支持完成回调的I / O函数,则可以使用该回调实现类似的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM