unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, StdCtrls, ComCtrls, ToolWin, Clipbrd, ExtCtrls;

type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    CopyButton: TToolButton;
    PasteButton: TToolButton;
    ToolButton4: TToolButton;
    ExitButton: TToolButton;
    ImageList1: TImageList;
    Image1: TImage;
    procedure CopyButtonClick(Sender: TObject);
    procedure PasteButtonClick(Sender: TObject);
    procedure ExitButtonClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FClipboardOwner:HWnd;
    procedure WMDrawClipboard(var Msg: TWMDrawClipboard); message WM_DRAWCLIPBOARD;
    procedure ClipboardChanged;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CopyButtonClick(Sender: TObject);
begin
 Clipboard.Assign(Image1.Picture);
end;

procedure TForm1.PasteButtonClick(Sender: TObject);
begin
 Image1.Picture.Assign(Clipboard);
end;

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

procedure TForm1.WMDrawClipboard(var Msg: TWMDrawClipboard);
begin
 SendMessage(FClipboardOwner, WM_DRAWCLIPBOARD, 0, 0);
 Msg.Result := 0;
 ClipboardChanged;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 FClipboardOwner := SetClipboardViewer(Handle);
 ClipboardChanged;
end;

procedure TForm1.ClipboardChanged;
var
 I: Integer;
begin
 PasteButton.Enabled := false;
 for I := 0 to Clipboard.FormatCount - 1 do
  begin
   if Clipboard.HasFormat(CF_BITMAP) then
    begin
     PasteButton.Enabled := True;
     Break;
    end;
  end;
end;

end.
