DELPHI中的编辑控件(如:Edit,Memo,RichEdit等)都有剪贴板操作过程。如: procedure TMainForm.EditCut(Sender: TObject); begin Editor.CutToClipboard; end;procedure TMainForm.EditCopy(Sender: TObject); begin Editor.CopyToClipboard; end;procedure TMainForm.EditPaste(Sender: TObject); begin Editor.PasteFromClipboard; end; 上述是RichEdit操作剪贴板的操作语句。 另外DELPHI有专门一个单元:Clipbrd,引用这个单元后,就可以在代码中操作剪贴板。下面是DELPHI说明示例: The following code locks the memory for text on the Clipboard, then reads the text.var MyHandle: THandle; TextPtr: PChar; MyString: string; begin ClipBoard.Open; try MyHandle := Clipboard.GetAsHandle(CF_TEXT); TextPtr := GlobalLock(MyHandle); MyString := StrPas(TextPtr); GlobalUnlock(MyHandle); finally Clipboard.Close; end; end;
uses Clipbrd;procedure TForm1.Button1Click(Sender: TObject); var Abmp:Tbitmap; begin Image1.Picture.Metafile.Assign(ClipBoard); Abmp := Tbitmap.Create; Abmp.Height:=Image1.Picture.Metafile.Height; Abmp.Width:=Image1.Picture.Metafile.Width; Abmp.Canvas.Draw(0,0,Image1.Picture.Metafile); Abmp.SaveToFile ('c:\abcd.bmp'); Abmp.free; end;
procedure TMainForm.EditCut(Sender: TObject);
begin
Editor.CutToClipboard;
end;procedure TMainForm.EditCopy(Sender: TObject);
begin
Editor.CopyToClipboard;
end;procedure TMainForm.EditPaste(Sender: TObject);
begin
Editor.PasteFromClipboard;
end;
上述是RichEdit操作剪贴板的操作语句。
另外DELPHI有专门一个单元:Clipbrd,引用这个单元后,就可以在代码中操作剪贴板。下面是DELPHI说明示例:
The following code locks the memory for text on the Clipboard, then reads the text.var MyHandle: THandle;
TextPtr: PChar;
MyString: string;
begin
ClipBoard.Open;
try
MyHandle := Clipboard.GetAsHandle(CF_TEXT);
TextPtr := GlobalLock(MyHandle);
MyString := StrPas(TextPtr);
GlobalUnlock(MyHandle);
finally
Clipboard.Close;
end;
end;
var
Abmp:Tbitmap;
begin
Image1.Picture.Metafile.Assign(ClipBoard);
Abmp := Tbitmap.Create;
Abmp.Height:=Image1.Picture.Metafile.Height;
Abmp.Width:=Image1.Picture.Metafile.Width;
Abmp.Canvas.Draw(0,0,Image1.Picture.Metafile);
Abmp.SaveToFile ('c:\abcd.bmp');
Abmp.free;
end;
http://topic.csdn.net/u/20110911/13/6aa14ed1-823a-40a6-9188-7e70639b61a2.html