delphi 剪切板变量_delphi剪切板-监视剪贴板
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,
Clipbrd, jpeg; //Clipboard使用
type
TForm1 = class(TForm)
Image1: TImage;
ListBox1: TListBox;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
//處理WM_DRAWCLIPBOARD消息過程
procedure WMDrawClipBoard(var AMessage:TMessage);message WM_DRAWCLIPBOARD;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
//觀察鏈中下一個窗口句柄
NextClipHwnd:HWND;
{ TForm1 }
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//從觀察鏈中刪除本觀察窗口
ChangeClipboardChain(Handle, NextClipHwnd);
//將WM_DRAWCLIPBOARD消息傳遞到下一個觀察鏈中的窗口
SendMessage(NextClipHwnd, WM_CHANGECBCHAIN, Handle, NextClipHwnd);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//獲得觀察鏈中下一個窗口句柄
NextClipHwnd := SetClipBoardViewer(Handle);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
if ListBox1.Items.Count >= 0 then
if ListBox1.Items.Strings[ListBox1.ItemIndex] ?='Bitmap' ?then
begin
Clipboard.Open;
Clipboard.Clear;
Clipboard.SetAsHandle(CF_BITMAP, Image1.Picture.Bitmap.Handle);
Clipboard.Close;
end
else
begin
Clipboard.Open;
ClipBoard.Clear;
Clipboard.AsText := ListBox1.Items.Strings[ListBox1.ItemIndex];
ClipBoard.Close;
end;
end;
procedure TForm1.WMDrawClipBoard(var AMessage: TMessage);
begin
//將WM_DRAWCLIPBOARD消息傳遞到下一個觀察鏈中的窗口
if NextClipHwnd <> 0 then
SendMessage(NextClipHwnd, AMessage.Msg, AMessage.WParam, AMessage.LParam);
//處理剪貼板中內(nèi)容
if Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT) then
begin
//查詢剪貼板中特定格式的數(shù)據(jù)內(nèi)容
ListBox1.Items.Add(Clipboard.asText + '...');
end;
if Clipboard.HasFormat(CF_BITMAP) then
begin
ListBox1.Items.Add('Bitmap');
Image1.Picture.Bitmap.LoadFromClipboardFormat(CF_BITMAP, clipboard.GetAsHandle(CF_BITMAP), 0);
end;
end;
end.
總結(jié)
以上是生活随笔為你收集整理的delphi 剪切板变量_delphi剪切板-监视剪贴板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【BZOJ3811】玛里苟斯(线性基)
- 下一篇: 2018秋c语言程序设计考试答案,201