unit Unit1;
interface
uses
; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
; Menus, StdCtrls, ComCtrls,Clipbrd;
type
; TForm1 = class(TForm)
; ; RichEdit1: TRichEdit;
; ; PopupMenu1: TPopupMenu;
; ; N1: TMenuItem;
; ; N2: TMenuItem;
; ; pastemenuitem: TMenuItem;
; ; procedure pastemenuitemClick(Sender: TObject);
; ; procedure FormCreate(Sender: TObject);
; ; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
; private
; ; { Private declarations }
; public
; ; { Public declarations }
; ; NextClipHwnd:HWND;//观察链中下一个窗口句柄
; ; procedure WMDrawClipboard (var AMessage:TMessage);message WM_DRAWCLIPBOARD;//剪贴板变化消息
; end;
var
; Form1: TForm1;
; en:boolean;
implementation
{$R *.DFM}
procedure TForm1.pastemenuitemClick(Sender: TObject);
begin
; richedit1.PasteFromClipboard;
end;
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
; ; //处理剪贴板中内容
; ; richedit1.Lines.Add(Clipboard.asText);
; ; pastemenuitem.Enabled:=true;
; end
; else pastemenuitem.Enabled:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//获得观察链中下一个窗口句柄
; NextClipHwnd:=SetClipBoardViewer(Handle);
; if (Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT))
; ;then pastemenuitem.Enabled:=true
; ;else pastemenuitem.Enabled:=false;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
; //+++++++++++++++可有可无++++++++++++++++
; //从观察链中删除本观察窗口
; ChangeClipboardChain(Handle,NextClipHwnd);
; //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口
; SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,Handle,NextClipHwnd);
end;
end.