用BCB做一个自己的Color Dector --- 实时显示鼠标所在位置的像素值

来源:互联网 发布:ubuntu tty 编辑:程序博客网 时间:2024/04/30 16:26

      两年前, 我做过一段时间的iOS开发, 我记得自己用过这样一个工具: 该工具可以实时显示鼠标所在位置的像素值。 下面, 我自己用BCB来做一个这样的工具, 代码如下(定时时间间隔为10ms):

//---------------------------------------------------------------------------#include <vcl.h>#pragma hdrstop#include "Unit1.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)    : TForm(Owner){}//---------------------------------------------------------------------------void __fastcall TForm1::Timer1Timer(TObject *Sender){    HDC hDC = GetWindowDC(NULL);    TPoint Pos = Mouse->CursorPos;    COLORREF nColor = GetPixel(hDC, Pos.x, Pos.y);    ReleaseDC(NULL, hDC);    BYTE R = GetRValue(nColor);    BYTE G = GetGValue(nColor);    BYTE B = GetBValue(nColor);    Label1->Caption = IntToStr(R);    Label2->Caption = IntToStr(G);    Label3->Caption = IntToStr(B);}//---------------------------------------------------------------------------
       我和专业的工具进行了对比, 发现所得的值完全一致, 以后我就可以用自己这个小工具了, 有点意义微笑



0 0