unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Clipbrd; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var Format: Word; Data: Cardinal; APalette: HPALETTE; begin {TBitmap.SaveToClipboardFormat 函数的三个参数都是接受数据用的, 按要求类型定义即可} GetFormImage.SaveToClipboardFormat(Format, Data, APalette); {放入剪切板} Clipboard.SetAsHandle(Format, Data); end; procedure TForm1.Button2Click(Sender: TObject); var dc: HDC; bmp: TBitmap; Format : Word; Bitmap : TBitMap; Data: THandle; Palette: HPALETTE; begin dc := GetDC(0); if dc <> 0 then begin bmp := TBitmap.Create(); bmp.Width := Width; bmp.Height := Height; BitBlt(bmp.Canvas.Handle, 0, 0, Width, Height, dc, Left, Top, SRCCOPY); bmp.SaveToClipboardFormat(Format, Data, Palette); Clipboard.SetAsHandle(Format, Data); bmp.Free(); ReleaseDC(0, dc); end; end;
参考:http://www.cnblogs.com/key-ok/p/3380436.html
时间: 2024-10-20 09:05:29