这是一个小程序,主要功能是获取当前鼠标的坐标和颜色值。主要用到两个win32 api 函数, 一个是GetCursorPos()//得到鼠标坐标 一个是GetPixel()//得到当前坐标下屏幕的颜色值 代码如下。 #include <iostream> #include <windows.h> using namespace std; bool IsMouseMove(); int main(void) { POINT p,o; A: if (IsMouseMove()) { HDC hDC=GetDC(NULL); //取得屏幕dc GetCursorPos(&p);//得到鼠标坐标 COLORREF clr; clr=GetPixel(hDC,p.x,p.y); int r=GetRValue(clr); //分解出红色值 int g=GetGValue(clr); //分解出绿色值 int b=GetBValue(clr); //分解出蓝色值 system("cls"); cout<<"鼠标坐标"<<p.x<<"/t"<<p.y<<endl; cout<<"当前颜色"<<r<<"/t"<<g<<"/t"<<b<