Cursor pos relative to window

Hello. I am trying to get cursor position relative to window. So what i want to be doing is to locate whatever window i am looking for, this i am doing by using the

FindWindowA(NULL, "winTitle");

function. Then i use

ScreenToClient(HWND hwnd, LPPoint point);

to try to get cordinates of that window relative to the screen. I need the cordinates of my given window, so that i can perform consistent mouse clicks to that window. Say if i need to fire a mouse click to the coordinate (100, 100) that is relative to my notepad window. Then i would get cordinates of notepad window, and then do the pseudo following

perform_mouse_down_click(notepad.x + 100, notepad.y + 100);

I have tried to use this code, and all it does is returning -8915849.

HWND hwnd = FindWindowA(NULL, "Untitled - Notepad");
ScreenToClient(hwnd, &p);
cout << p.x << " : " << p.y << endl;

ScreenToClient(FindWindowA(NULL, "Untitled - Notepad"), &p);

Did the trick, no help needed!
Registered users can post here. Sign in or register to post.