这可能是一个愚蠢的问题,但就在这里。
假设您正在与驱动程序 API 进行交互。您正在使用 C 并完全通过命令提示符进行操作。没有图形用户界面。是否可以接收和处理此类文件中的 Windows 消息?
我的意思是,在任何地方,我都将 Windows 句柄用作 NULL。我不知道这是否可能,甚至是否有意义。
最佳答案
要使用 GetMessage 或 PeekMessage,您的线程中不需要任何窗口:http://msdn.microsoft.com/en-us/library/ms644946%28v=vs.85%29.aspx
The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails.
Use the following method to handle this situation.
Create an event object, then create the thread.
Use the WaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage.
In the thread to which the message will be posted, call PeekMessage as shown here to force the system to create the message queue:
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) > Set the event, to indicate that the thread is ready to receive posted messages. The thread to which the message is posted retrieves the message by calling the GetMessage or PeekMessage function. The hwnd member of the returned MSG structure is NULL.
关于c - 使用基于命令的编译器与 Windows 消息交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17295799/