将Windows消息发送到控制台应用程序

问题描述:

我有一个DLL向UI应用程序发送消息,该DLL发送的大多数消息中都包含文本,GUI应用程序获取消息并根据消息进行操作.

I have a DLL that send message to the UI application, most of the messages that the DLL send contains text in them, the GUI application get the message and act according to the message.

我需要创建一个使用相同DLL的控制台应用程序,是否有任何选项可以将消息发送到控制台应用程序,因为在控制台应用程序中我没有Windows消息过程.

I need to create a console application that works with the same DLL, Is there any option to get the messages to the console application, as in console application I do not have a windows message procedure.

在GUI应用程序中,我加载DLL并使用其功能之一将当前的HWND设置为DLL,一旦执行此操作,所有消息就会发送到我的GUI.

In the GUI application I load the DLL and use one of its function to set my current HWND to the DLL, once I do this all the messages are send to my GUI.

我曾考虑过向DLL添加一个布尔值,以了解是从GUI界面还是从命令行控制台应用程序调用了DLL,但这涉及DLL代码的许多更改.

I thought about adding a Boolean value to the DLL to know if the DLL was call from the GUI interface or from the command line console application, but that involve a lot of changes in the DLL code.

如何获取消息或将消息重定向到控制台应用程序(命令行界面)?

How can I get or redirect the messages to the console application (command line interface)?

使用Win32 API以C/C ++编码DLL,GUI和控制台应用程序.

The DLL, GUI and console application are coded in C/C++ using the win32 API.

预先感谢

您可以在控制台应用程序中创建窗口,就像在标准Windows应用程序中一样.如果您创建仅消息窗口(设置为调用 CreateWindow())时窗口的父窗口为 HWND_MESSAGE ),则该窗口的父窗口将不可见,但仍将能够接收Windows消息.您需要在控制台应用程序中的某个位置运行标准的Windows消息循环,以便将消息发送到窗口.

You can create a window in a console application, just like in a standard Windows application. If you create a message only window (set the parent of the window to HWND_MESSAGE when calling CreateWindow()), then it won't be visible, but will still be able to receive Windows messages. You will need to have the standard Windows message loop running somewhere in your console application in order for the messages to be dispatched to your window.