procedure Tform1.TimerTimer(Sender: TObject);
var
Pos: TPoint;
Handle: HWND;
ScreenDC: HDC;
Buf: array[0..1024] of Char;
ScreenColor: COLORREF;
begin
GetCursorPos(Pos); // 得到當前光標位置
Handle := WindowFromPoint(Pos); // 返回當前位置的句柄
HandleText.Caption := IntToStr(Handle);
GetClassName(Handle, Buf, 1024); // 得到類名
ClassNameText.Caption := Buf;
SendMessage(Handle, WM_GETTEXT, 33, Integer(@Buf)); // 得到標題
TitleText.Caption := Buf;
{ 得到光標處點的顏色 }
ScreenDC := GetDC(0);
ScreenColor := GetPixel(ScreenDC, Pos.X, Pos.Y);
Shape.Brush.Color := TColor(ScreenColor);
RGBColorText.Caption := '紅: ' + IntToStr(GetRValue(ScreenColor)) +
' 綠: ' + IntToStr(GetGValue(ScreenColor)) + ' 藍: ' +
IntToStr(GetBValue(ScreenColor));
ReleaseDC(0, ScreenDC);
DelphiColorText.Caption := Format('Delphi中顏色值:$00%2.2x%2.2x%2.2x', [GetBValue(ScreenColor),
GetGValue(ScreenColor), GetRValue(ScreenColor)]);
HTMLColorText.Caption := Format('Html顏色值:#%2.2x%2.2x%2.2x', [GetRValue(ScreenColor),
GetGValue(ScreenColor), GetBValue(ScreenColor)]);
end;