1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Clipbrd ;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SubClassWndProc(var Message: TMessage);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
OldWindowProc:TWndMethod;
Clipboard:TClipboard;
implementation
{$R *.DFM}
procedure TForm1.SubClassWndProc(var Message: TMessage);
var MyHandle: THandle;
TextPtr: PChar;
MyString: string;
begin
if (message.Msg=WM_PASTE) // analyse du clipboard avant le coller
then
begin
if Clipboard.HasFormat(49280) // en provenance d'IE
then
begin
ClipBoard.Open;
try
MyHandle := Clipboard.GetAsHandle(49280);
TextPtr := GlobalLock(MyHandle);
MyString := StrPas(TextPtr);
memo1.text:=Mystring;
GlobalUnlock(MyHandle);
finally
Clipboard.Close;
end;
end
else OldWindowProc(Message); // methode par defaut
end
else OldWindowProc(Message);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OldWindowProc:=memo1.WindowProc;
memo1.WindowProc:=SubClassWndProc;
Clipboard:=TClipboard.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
var I: Integer;
begin
listbox1.Items.Clear;
for I := 0 to Clipboard.FormatCount-1 do
ListBox1.Items.Add(IntToStr(Clipboard.Formats[I]));
end;
end. |