【发布时间】:2019-11-26 10:14:18
【问题描述】:
我正在尝试读取屏幕的某个区域并遍历该区域,如果某个红点穿过该区域,请单击鼠标左键。我想我已经接近解决我的问题了,但是我搜索了很多,但没有找到任何解决方案。另外,如果我的代码有问题,请告诉我,因为我正在尝试使用位图,但我对此了解不多。
这是我的问题的图像表示(我没有 10 个代表来发布图像):
只需要读取绿色区域。
int main()
{
LPCWSTR windowTitle = L"window_name";
HWND hwnd = FindWindow(NULL, windowTitle);
HDC hdcSource, hdcMemory;
BYTE* bitPointer;
POINT cursorPosition;
int red, green, blue;
int x = 140;
int y = 205;
int width = 1920 - 1760;
int height = 1080 - 875;
while (true)
{
int width = 1920 - 1760;
int height = 1080 - 875;
hdcSource = GetDC(hwnd);
hdcMemory = CreateCompatibleDC(hdcSource);
int capX = GetDeviceCaps(hdcSource, HORZRES);
int capY = GetDeviceCaps(hdcSource, VERTRES);
HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, width, height);
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hBitmap);
BitBlt(hdcMemory, 0, 0, width, height, hdcSource, x, y, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hdcMemory, hBitmapOld);
// Loop through bitmap selection and if find the RGB color (220, 0 , 0) click with left mouse button
for (int i = 0; ???; i++)
{
// something here
if (red == 220 && green == 0 && blue == 0)
{
GetCursorPos(&cursorPosition);
mouse_event(MOUSEEVENTF_LEFTDOWN, cursorPosition.x, cursorPosition.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, cursorPosition.x, cursorPosition.y, 0, 0);
}
}
ReleaseDC(NULL, hdcSource);
ReleaseDC(NULL, hdcMemory);
}
}
【问题讨论】: