unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Panel2: TPanel;
    procedure FormPaint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);

  private

  public
    procedure Rysuj();
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
	Close();
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Invalidate();
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
	Rysuj();
end;

procedure TForm1.Rysuj();
var
	h   : HWND;
   dc  : HDC;
   txt : String;

begin
   txt := 'Na panelu';
   h   := Panel2.Handle;

   dc := GetDC(h);
   TextOut(dc, 15, 5, PAnsiChar(txt), Length(txt));
   ReleaseDC(h, dc);

   // tak samo dla Button1
   h := FindWindow(Nil, 'Button1');

   if h = 0 then
   begin
		// ShowMessage(IntToStr(h));
   end
   else begin
	   txt := 'Na buttonie';
	   h  := Button1.Handle;
	   dc := GetDC(h);
      TextOut(dc, 15, 5, PAnsiChar(txt), Length(txt));
      ReleaseDC(h, dc);
   end;
end;

end.

