The Win32 function "SendInput" is what you want...
Here is how to simulate a left-click...
void LeftClick()
{
INPUT Input={0};
// left down
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,&Input,sizeof(INPUT));
}
So then just call LeftClick() and a left-click will be simulated. This only allows you to click on the current mouse position. If you want to first move the mouse use this function...
void MouseMove(int x, int y )
{
double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1;
double fScreenHeight = ::GetSystemMetrics( SM_CYSCREEN )-1;
double fx = x*(65535.0f/fScreenWidth);
double fy = y*(65535.0f/fScreenHeight);
INPUT Input={0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
SendInput(1,&Input,sizeof(INPUT));
}