相关资料:
http://user.qzone.qq.com/513187410/blog/1265981516
实例原码:
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls, ExtCtrls, 8 Clipbrd, jpeg; //Clipboard使用 9 10 type11 TForm1 = class(TForm)12 Image1: TImage;13 ListBox1: TListBox;14 Image2: TImage;15 procedure FormCreate(Sender: TObject);16 procedure FormClose(Sender: TObject; var Action: TCloseAction);17 procedure ListBox1Click(Sender: TObject);18 private19 { Private declarations }20 //处理WM_DRAWCLIPBOARD消息过程21 procedure WMDrawClipBoard(var AMessage:TMessage);message WM_DRAWCLIPBOARD;22 public23 { Public declarations }24 end;25 26 var27 Form1: TForm1;28 29 implementation30 { $R *.dfm}31 32 var33 //观察链中下一个窗口句柄34 NextClipHwnd:HWND;35 { TForm1 }36 37 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);38 begin39 //从观察链中删除本观察窗口40 ChangeClipboardChain(Handle, NextClipHwnd);41 //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口42 SendMessage(NextClipHwnd, WM_CHANGECBCHAIN, Handle, NextClipHwnd);43 end;44 45 procedure TForm1.FormCreate(Sender: TObject);46 begin47 //获得观察链中下一个窗口句柄48 NextClipHwnd := SetClipBoardViewer(Handle);49 end;50 51 procedure TForm1.ListBox1Click(Sender: TObject);52 begin53 if ListBox1.Items.Count >= 0 then 54 if ListBox1.Items.Strings[ListBox1.ItemIndex] ='Bitmap' then55 begin56 Clipboard.Open;57 Clipboard.Clear;58 Clipboard.SetAsHandle(CF_BITMAP, Image1.Picture.Bitmap.Handle);59 Clipboard.Close;60 end61 else62 begin63 Clipboard.Open;64 ClipBoard.Clear;65 Clipboard.AsText := ListBox1.Items.Strings[ListBox1.ItemIndex];66 ClipBoard.Close;67 end;68 end;69 70 procedure TForm1.WMDrawClipBoard(var AMessage: TMessage);71 begin72 //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口73 if NextClipHwnd <> 0 then74 SendMessage(NextClipHwnd, AMessage.Msg, AMessage.WParam, AMessage.LParam);75 //处理剪贴板中内容76 if Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT) then77 begin78 //查询剪贴板中特定格式的数据内容79 ListBox1.Items.Add(Clipboard.asText + '...');80 end;81 if Clipboard.HasFormat(CF_BITMAP) then82 begin83 ListBox1.Items.Add('Bitmap');84 Image1.Picture.Bitmap.LoadFromClipboardFormat(CF_BITMAP, clipboard.GetAsHandle(CF_BITMAP), 0);85 end;86 end;87 88 end.