I think it is the use of SendMessage function that I need help with but I'm not entirely sure if I'm even going about this in the right way so I will explain from the start.
Basically, what I want is a program to perform a tedious task and then when it has performed the actions to quit. It's not completly necessary but I was playing around with it and thought I would like to know how to do it for future reference. What I have coded so far uses GetCursorPos, SetCursorPos etc to actually move my cursor around and perform the tasks for me but what I'm looking to do now is to make it so I can do other actions at the same time. For example, I can have the application and my program both minimized and they will do thier own thing and exit when done.
I'm guessing this will involve using FindWindow and SendMessage but I cannot get this to work. I have so far used FindWindow to get the applications handle but the SendMessage appears to do nothing. I'm not sure if it is me using SendMessage wrong (could someone please explain how to use this correctly?) or if it's the whole method I'm doing wrong.
Below is what I've tried so far. I've been using notepad just as a test.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
HWND hNote;
hNote = FindWindow(NULL, "Untitled - Notepad");
bool sent = SendMessage(hNote, WM_KEYDOWN, VK_RETURN, 0);
cout << sent << endl;
cout << "Press return to exit...";
cin.get();
return 0;
}
Sent returns as false and the enter key action is not performed in notepad (ie there is no new line). I have also tried change hNote to FindWindow("Edit", NULL) as I downloaded a program the gives the class name and and caption name etc of a selected window and if I highlighted the edit part of the Notepad file it gave me that class with no caption. But on doing so hNote started returning 0.
Any help would be appreciated and sorry if this isn't too clear.