How to detect clipboard change

Detecting clipboard change is very similar to detecting system time change. We will detect WM_DRAWCLIPBOARD system message.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ClipBoardChanged(var Message: TMessage); message WM_DRAWCLIPBOARD;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ClipBoardChanged(var Message: TMessage);
begin
  ShowMessage('Clipboard changed!');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetClipboardViewer(Handle);
end;

end.

Leave a Reply