Knowledge Base Nr: 00233 maussim.cpp - http://www.swe-kaiser.de

Win32: Maus simulieren (Cursor- und Maustastensimulation)

  
void CCursortestDlg::DoCursorPosLesen()
{
POINT point;

::GetCursorPos(&point);

CString strX, strY;

strX.Format("%d", point.x);
strY.Format("%d", point.y);

GetDlgItem(IDC_EDIT1)->SetWindowText(strX);
GetDlgItem(IDC_EDIT2)->SetWindowText(strY);
}

void CCursortestDlg::DoMouseButtonClick()
{
CString strX, strY;

GetDlgItem(IDC_EDIT1)->GetWindowText(strX);
GetDlgItem(IDC_EDIT2)->GetWindowText(strY);

//cursor positionieren...
::SetCursorPos(atoi(strX), atoi(strY));

//...mousetaste drücken...
mouse_event(MOUSEEVENTF_LEFTDOWN, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);

//..kurz gedrückt halten...
Sleep(100);

//...und loslassen
mouse_event(MOUSEEVENTF_LEFTUP, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);
}