What I am trying to do is simply get a coordinate system in which to run mouse commands in a window I have the handle to.
What I am trying to do is macro my mouse. The catch is my mouse pointer has to move along with commands such as LBUTTONDOWN\LBUTTON UP.
I am trying to automate a drag and drop sequence. So when my program finds what its supposed to it will move the mouse to that area of the window and click the left mouse button down then drag the item to a specified zone and drop it.
This is far more trivial than I thought it would be, and I am begging for help on this one after hours of googling, and no code I can find is relating to what I am trying to do. Im not trying to make a drag and drop file program. It's as simple as in this programs window I have to drag and drop icons from point A to point B. So I have loops and using getpixel(); to find what I am looking for I am half way there. Once the icon is found I tried sending WM_LBUTTONDOWN to the found coordinates, and using math to logically drag the icon however it did not work nor even dragged the icon. So I am assuming my actual mouse icon for this applications window must be over the icon for this to work properly.
I am working and reworking code, but the outcome is always the same. My mouse pointer goes to the top left of my desktop screen and not of the hwnd window I am wanting this to work within.
int AutoMateMouseMacro()
{ //code for goldpickup hotkey being pressed.
POINT point;
SetCursorPos(0,0);
GetCursorPos(&point);
RECT rect;
GetClientRect(hwndDC,&rect);
int ytop = rect.top;
int ybottom = rect.bottom;
int xleft = rect.left;
int xright = rect.right;
while(ytop <= ybottom)
{
point.y = ytop;
ytop++;
if(ytop == ybottom)
{
point.y = ytop - ybottom;
ytop = point.y;
break;
};
};
while(xleft <= xright)
{
point.x = xleft;
xleft++;
if(xleft == xright)
{
point.x = xleft - xright;
xleft = point.x;
ScreenToClient(hwndDC,&point);
GetCursorPos(&point);
SetCursorPos(xleft,ytop);
break;
};
};
if(point.x >= xleft && point.x <= xright && point.y >= ytop && point.y <= ybottom)
{ // Your inside the client rect area
MessageBox(hwndDC,"Your Are INSIDE the Client Zone","WOOO HOOO", MB_OK|MB_ICONINFORMATION);
SendMessage(hwndDC,WM_RBUTTONDOWN,0,MAKELPARAM(point.x,point.y));
SendMessage(hwndDC,WM_RBUTTONDOWN,0,MAKELPARAM(point.x,point.y));
SendMessage(hwndDC,WM_RBUTTONDOWN,0,MAKELPARAM(point.x,point.y));
SendMessage(hwndDC,WM_RBUTTONDOWN,0,MAKELPARAM(point.x,point.y));
SendMessage(hwndDC,WM_RBUTTONDOWN,0,MAKELPARAM(point.x,point.y));
}
else
{
// Your out of the client rect
MessageBox(hwndDC,"Your Are Outside the Client Zone","Warning Box", MB_OK|MB_ICONINFORMATION);
};
return 0;
};
What am I doing wrong here?
The mouse pointer keeps getting set to the top left corner of the screen.
However I know I have the proper HWND, because all the other functions work properly, and my error check for the HWND to the applications window is not failing.
I am simply doing something wrong, and dont know exactly what.
Ive been on this problem all morning with the same outcome.
Help would be very appreciated.