Communicate between multiple windows?

This might seem like a simple question, but is there a way for me to make several windows (console for now, until I feel like installing Boost) that run from different processes, (for example, the user clicks the .exe file twice and opens two separate instances of the program) but can interact?
Specifically, I would like them to interact using their positions on the screen-designed so that if the two have edges that are touching and are lined up, they send data between the two.

How would I go about getting the positions on the screen, and what is the easiest way to handle the interaction? I don't want to resort to mailbox files unless it's REALLY necessary.
No need to use mailbox files. I don't know how to do it with a console, but, if you have two windows, you can just send user-defined messages using WM_USER.

1
2
3
#define IS_TOUCHING	WM_USER
#define IS_LINED	WM_USER + 1
// ... etc. 
See RegisterWindowMessage() for information on getting a message ID your application can use to talk to other instances of itself or other applications:
http://www.google.com/search?btnI=1&q=msdn+RegisterWindowMessage

The message itself is a MSG structure: http://www.google.com/search?btnI=1&q=msdn+MSG
The items of interest are wParam and lParam -- these are how you can send codes to each other. There is also a pt member that you can co-opt (it is used in mouse messages and the like).

What I would do, actually, is just broadcast your unique message ID (obtained via RegisterWindowMessage()) every time one of your windows is moved or mapped, with a wParam indicating that the application is looking for communication and an lParam with the originator's HWND.

Also, listen for the same message ID in your application. Once the message is received, it can check to see if touching using GetWindowRect() on the two windows and comparing the results.
http://www.google.com/search?btnI=1&q=msdn+GetWindowRect

If the windows are satisfiably aligned then the listener can send back that it wants to talk with a different code in wParam.

To actually send strings (or other things) between applications, you can use the WM_COPYDATA message. See the following articles:

Inter Process Communication via WM_COPYDATA
http://www.codeguru.com/cpp/w-p/system/processesmodules/article.php/c5777

TechBlog - IPC with WM_COPYDATA
http://blog.hansentech.com/mhblog_2008_11_19.html

To use this method, your application will need to create a hidden window with a proper window procedure attached.

Well, that should be enough to get you started. Good luck!
Topic archived. No new replies allowed.