I have been programming in C++11 on a 32 bit Windows operating system. When I run the program it is difficult for me to follow what it is doing. I am now attempting to have my program open up Wordpad seperately and write to Wordpad as my program executes a command or does something that I want to record there.
I have tried this with NotePad and that works OK. But, I want to be able to use Wordpad since it holds a lot more.
Here is where I am:
I added some, but I am lost in what is going on. Suggestions please.
What I have tried:
<pre> STARTUPINFO si = {};
si.cb = sizeof si;
PROCESS_INFORMATION pi = {};
LPCWSTR target = L"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe";
if ( !CreateProcess(target, nullptr, nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi) )
{
MessageBox(nullptr, L"CreateProcess failed for notepad .", L"Error!", MB_ICONEXCLAMATION | MB_OK);
}
else
{
WaitForSingleObject(pi.hProcess, 1);
cout << L"\nYou have entered an empty reply, please try again...";
}
<pre> STARTUPINFO si2;
PROCESS_INFORMATION pi2;
ZeroMemory( &si2, sizeof(si2) );
si2.cb = sizeof(si2);
ZeroMemory( &pi2, sizeof(pi2) );
CreateProcess
(
TEXT("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"),
NULL,NULL,NULL,FALSE,
CREATE_NEW_CONSOLE,
NULL,NULL,
&si2,
&pi2
);
cout << "Unable to execute.";
HWND handle = FindWindow(NULL,L"Untitled - Notepad");
HWND edit = FindWindowEx(handle, NULL, L"Edit", NULL);
PostMessage(edit, WM_CHAR, 'a', 0 );
And how do I do this in Wordpad instead of Notepad?