mình có sử dụng 2 hàm main như bên dưới, hàm Main1 thì lấy đúng mã màu RGB của tất cả các điểm trên màn hình, nhưng khi mình dùng hàm main2 thì nó vẫn lấy đúng toạ độ của điểm theo ứng dụng mình cần lấy nhưng lại trả về sai giá trị RGB
==> Xin các bác hỗ trợ giúp cách fix lỗi này
#include <iostream>
#include <Windows.h>
using namespace std;
int main1() {
POINT pos;
int R;
int G;
int B;
while (1) {
GetCursorPos(&pos);
HDC hDC = GetDC(NULL);
COLORREF color = GetPixel(hDC, pos.x, pos.y);
R = GetRValue(color);
G = GetGValue(color);
B = GetBValue(color);
std::cout << "x : " << pos.x << ", y : " << pos.y << ", R : " << R << ", G : " << G << ", B : " << B << endl;
ReleaseDC(NULL, hDC);
Sleep(1000);
}
return 0;
}
int main2() {
POINT pos;
int R;
int G;
int B;
while (1) {
LPCWSTR window_title = L"HxD";
HWND hWND = FindWindow(NULL, window_title);
while (!hWND)
{
hWND = FindWindow(NULL, window_title);
cout << "not found window"<<endl;
Sleep(1000);
}
GetCursorPos(&pos);
ScreenToClient(hWND, &pos);
HDC hDC = GetDC(hWND);
COLORREF color = GetPixel(hDC, pos.x, pos.y);
R = GetRValue(color);
G = GetGValue(color);
B = GetBValue(color);
std::cout << "x : " << pos.x << ", y : " << pos.y << ", R : " << R << ", G : " << G << ", B : " << B << endl;
ReleaseDC(hWND, hDC);
Sleep(1000);
}
return 0;
}