c - 使用基于命令的编译器与 Windows 消息交互

标签 c winapi command-line windows-messages

这可能是一个愚蠢的问题,但就在这里。

假设您正在与驱动程序 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/

相关文章:

c - 为什么访问我的结构会减慢我的方法执行速度

c# - 如何处理 .NET 5 控制台应用程序中任务管理器中的 "End Task"?

ruby - 在Ruby中实现过程输出的最佳方法

c - 如何修复由于递归算法引起的段错误

c - USART接收中断stm32

c++ - C/C++ 中的 C 风格无符号字符解析和操作 - 段错误

unix - 确定文本文件中唯一性和重复性的最佳方法

c - fscanf() 返回负值

Python win32api 发送消息

windows - 通过调用名称在 Windows 中调用 Ghostscript?