unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,Clipbrd;//加入clipbrd单元
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
NextClipHwnd:HWND;//观察链中下一个窗口句柄
procedure WMDrawClipBoard(var AMessage:TMessage);
message WM_DRAWCLIPBOARD;//处理WM_DRAWCLIPBOARD消息过程
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WMDrawClipBoard(var AMessage: TMessage);
begin
//将WM_DRAWCLIPBOARD
消息传递到下一个观察链中的窗口
SendMessage(NextClipHwnd,AMessage.
Msg,AMessage.WParam,AMessage.LParam);
//查询剪贴板中特定格式的数据内容
if (Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT)) then
begin
//处理剪贴板中内容
Clipboard.Clear;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//获得观察链中下一个窗口句柄
NextClipHwnd:=SetClipBoardViewer(Handle);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//从观察链中删除本观察窗口
ChangeClipboardChain(Handle,NextClipHwnd);
//将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口
SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,Handle,NextClipHwnd);
end;
end.