interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Clipbrd; {剪切板單元}
//把窗體客戶區保存為圖片
procedure TForm1.Button1Click(Sender: TObject);
var
bit: TBitmap;
begin
bit := TBitmap.Create;
bit := Self.GetFormImage;
bit.SaveToFile('c:tempimg1.bmp');
bit.Free;
end;
//用一句話完成上一個過程
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.GetFormImage.SaveToFile('c:tempimg2.bmp');
end;
//把窗體客戶區圖像復制到剪切板
procedure TForm1.Button3Click(Sender: TObject);
var
Format: Word;
Data: Cardinal;
APalette: HPALETTE;
begin
{TBitmap.SaveToClipboardFormat 函數的三個參數都是接受數據用的, 按要求類型定義即可}
GetFormImage.SaveToClipboardFormat(Format, Data, APalette);
{放入剪切板}
Clipboard.SetAsHandle(Format, Data);
end;