How to Send and Receive Messages Between Windows Forms Applications
Environment
Product Version | Product | Author |
---|---|---|
2022.3.913 | UI for WinForms | Desislava Yordanova |
Description
This article demonstrates a general approach for transferring messages between two separate Windows Forms Applications.
Solution
It is necessary to create two separate Windows Forms Applications, one with name "SendMessagesApp" and another one called "ReceiveMessagesApp".
SendMessagesApp
ReceiveMessagesApp
We will use the SendMessage function passing WM_SETTEXT with the input available in a RadTextBox control. The FindWindowByCaption function is used for finding the handle of the "receiver" form. Then, the form that is expecting to receive the message from another application, should override its WndProc method and execute the desired action - in our case this will be inserting the text in a RadRichTextEditor.
This is the code added to the SendMessagesApp:
This is the code added to the ReceiveMessagesApp:
It is important to note that the Text of the receiver form is set to "ReceiveMessagesForm" since the handle is found by the caption.