Send windows message to a console application

╄→尐↘猪︶ㄣ 提交于 2021-02-10 12:46:14

问题


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.

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.

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.

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)?

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

Thanks in advance


回答1:


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.



来源:https://stackoverflow.com/questions/36043832/send-windows-message-to-a-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!