Please Help

So I found the program below online. It takes text from an open notepad and shows it to you on the program screen.

So my question is how could I make a c++ program that takes what you put into it and dumps it in another program? For example lets say I have Program 1 and Program 2. Program 2 is asking me to pick a random number, so I type 28 in Program 1 and it shows up in Program 2.

Let me say in advance that I really appreciate your answers guys. (Also I am a pretty unexperinced programmer so an explanation would be wonderful) Again thnx

// DumpNotepadText.cpp

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
using namespace std;

void DumpNotepadText()
{
cout << "[DumpNotepadText]" << endl;

cout << "- find Notepad window" << endl;
HWND hwndNotepad = FindWindow("Notepad", NULL);

if(NULL != hwndNotepad)
{
cout << "- find Edit control window" << endl;
HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, "EDIT", NULL);

if(NULL != hwndEdit)
{
cout << "- get text length" << endl;
int textLen = (int)SendMessage(hwndEdit, WM_GETTEXTLENGTH, 0, 0);

if(0 < textLen)
{
cout << "- get text (up to 1024 chars, inc term null)" << endl;
const int bufferSize = 1024;
char textBuffer[bufferSize] = "";
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);

cout << "[begin text]" << endl;
cout << textBuffer << endl;
cout << "[end text]" << endl;
}
else
{
cerr << "? No text there! :-(" << endl;
}
}
else
{
cerr << "? Huh? Can't find Edit control!?!" << endl;
}
}
else
{
cerr << "? No notepads open! :-(" << endl;
}
}

int main()
{
DumpNotepadText();

return 0;
}

The problem is generally described as Inter-Process Communication, IPC.

This link lists Windows IPC mechanisms.
http://msdn.microsoft.com/en-gb/library/windows/desktop/aa365574%28v=vs.85%29.aspx

Surprisingly, it doesn't mention the method used above, Windows Messaging.
Last edited on
Topic archived. No new replies allowed.