#include #include <Windows.h>

// 函数声明 bool IsColorMatch(COLORREF pixelColor, COLORREF targetColor); COLORREF GetPixelColor(int x, int y);

int main() { int targetX, targetY; COLORREF targetColor;

// 获取目标位置和颜色
std::cout << "请输入目标位置的X坐标:";
std::cin >> targetX;
std::cout << "请输入目标位置的Y坐标:";
std::cin >> targetY;
std::cout << "请输入指定颜色的RGB值(格式为RRGGBB):";
std::cin >> std::hex >> targetColor;

// 获取屏幕DC
HDC screenDC = GetDC(NULL);

// 获取目标位置的颜色
COLORREF pixelColor = GetPixelColor(targetX, targetY);

// 判断颜色是否匹配
bool isMatch = IsColorMatch(pixelColor, targetColor);

// 输出结果
if (isMatch) {
    std::cout << "颜色匹配!" << std::endl;
} else {
    std::cout << "颜色不匹配!" << std::endl;
}

// 释放屏幕DC
ReleaseDC(NULL, screenDC);

return 0;

}

// 判断颜色是否匹配 bool IsColorMatch(COLORREF pixelColor, COLORREF targetColor) { return pixelColor == targetColor; }

// 获取指定位置的颜色 COLORREF GetPixelColor(int x, int y) { HDC screenDC = GetDC(NULL); COLORREF pixelColor = GetPixel(screenDC, x, y); ReleaseDC(NULL, screenDC); return pixelColor; }

C++ Win32 屏幕颜色检测: 判断指定位置颜色是否匹配

原文地址: https://www.cveoy.top/t/topic/qrsp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录