按PrnScreen,在程序里截取剪贴板内容。
前两天参考别人的技巧做了个简单截取剪贴板的例子:
unit clip;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Clipbrd,
StdCtrls, ComCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
clip: TRichEdit;
Color: TBitBtn;
ColorDlg: TColorDialog;
Save: TBitBtn;
SaveDlg: TSaveDialog;
Image1: TImage;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ColorClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
NextClipHwnd:HWND
//观察链中下一个窗口句柄
procedure WMDrawClipBoard(var Amessage:Tmessage);
message WM_DRAWCLIPBOARD;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Tform1.WMDrawClipBoard(var Amessage: Tmessage);
begin
SendMessage(NextClipHwnd,Amessage.msg,amessage.WParam ,amessage.LParam );
//处理剪贴板的内容
if clipboard.hasformat(CF_TEXT) then
begin
Clip.Text :=clipboard.astext;
end;
if clipboard.HasFormat(CF_BITMAP) then
begin
Image1.Picture.bitmap.Assign (clipboard);
clipboard.Clear
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ChangeClipBOardChain(Handle,NextClipHwnd);
SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,handle,NextClipHwnd);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//获得观察链中下一个窗口句柄
NextClipHwnd :=setClipBoardViewer(Handle);
end;
procedure TForm1.ColorClick(Sender: TObject);
begin
if colordlg.Execute then
clip.SelAttributes.Color :=colordlg.Color
end;
procedure TForm1.SaveClick(Sender: TObject);
begin
if savedlg.execute then
clip.lines.SaveToFile(savedlg.filename)
end;
end.