procedure TForm1.Timer1Timer(Sender: TObject);
Var Pt:TPoint;
DC:HDC; Col:TColorRef; hBr,OldBr:HBrush;
begin
GetCursorPos(Pt);
DC:=CreateDC('
DISPLAY',
NIL,
NIL,
NIL);
// Desktop DC
Try
Col:=GetPixel(
DC,Pt.x,Pt.y);
hBr:=CreateSolidBrush(Col);
OldBr:=SelectObject(Canvas.Handle,hBr);
Rectangle(Canvas.Handle,10,10,100,100);
Finally
SelectObject(Canvas.Handle,OldBr);
DeleteObject(hBr);
DeleteDC(
DC);
End;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
Var DC:HDC; Wnd:HWnd; Rect:TRect; Pt:TPoint;
Col:TColorRef; hBr,OldBr:HBrush;
begin
GetCursorPos(Pt);
Wnd:=WindowFromPoint(Pt);
if GetWindowRect(Wnd, Rect)
then begin
DC:=GetWindowDC(Wnd);
// Window DC einschließlich NonClient Area
Try
Pt.X:=Pt.X-Rect.Left;
Pt.Y:=Pt.Y-Rect.Top;
GetPixel(
DC, Pt.X, Pt.Y);
Label1.Caption:=Format('
X:%d; Y:%d',[Pt.x,Pt.y]);
Col:=GetPixel(
DC,Pt.x,Pt.y);
hBr:=CreateSolidBrush(Col);
OldBr:=SelectObject(Canvas.Handle,hBr);
Rectangle(Canvas.Handle,200,10,300,100);
Finally
DeleteObject(hBr);
SelectObject(Canvas.Handle,OldBr);
ReleaseDC(Wnd,
DC);
End;
End;
end;