码迷,mamicode.com
首页 > 编程语言 > 详细

用C++获取屏幕上某点的颜色

时间:2019-07-05 14:22:52      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:pause   ret   颜色   outside   top   com   屏幕   gre   return   

假定坐标点 x=50,y=50. 输出 RGB 用 16 进制数。
Afxwin.h 你建项目时可得。
#include <Afxwin.h>
#include <Windows.h>
#pragma comment (lib, "User32.lib")

int main(void){
HWND hWnd = ::GetDesktopWindow();
HDC hdc = ::GetDC(hWnd);
// HDC hdc = ::GetDC(NULL);
int x=50,y=50;
COLORREF pixel = ::GetPixel(hdc, x, y);
if (pixel != CLR_INVALID) {
int red = GetRValue(pixel);
int green = GetGValue(pixel);
int blue = GetBValue(pixel);
printf("R=%x G=%x B=%x\n",red,green,blue);
} else {
printf("outside");
}
system("PAUSE");
return 0;
}

用C++获取屏幕上某点的颜色

标签:pause   ret   颜色   outside   top   com   屏幕   gre   return   

原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/11137949.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!