• 剪切板-监视剪贴板


    相关资料:

    http://user.qzone.qq.com/513187410/blog/1265981516 

    实例原码:

     1 unit Unit1;
     2 
     3 interface
     4 
     5 uses
     6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     7   Dialogs, StdCtrls, ExtCtrls,
     8   Clipbrd, jpeg; //Clipboard使用
     9 
    10 type
    11   TForm1 = class(TForm)
    12     Image1: TImage;
    13     ListBox1: TListBox;
    14     Image2: TImage;
    15     procedure FormCreate(Sender: TObject);
    16     procedure FormClose(Sender: TObject; var Action: TCloseAction);
    17     procedure ListBox1Click(Sender: TObject);
    18   private
    19     { Private declarations }
    20     //处理WM_DRAWCLIPBOARD消息过程
    21     procedure WMDrawClipBoard(var AMessage:TMessage);message WM_DRAWCLIPBOARD;
    22   public
    23     { Public declarations }
    24   end;
    25 
    26 var
    27   Form1: TForm1;
    28 
    29 implementation
    30 {$R *.dfm}
    31 
    32 var
    33   //观察链中下一个窗口句柄
    34   NextClipHwnd:HWND;
    35 { TForm1 }
    36 
    37 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    38 begin
    39   //从观察链中删除本观察窗口
    40   ChangeClipboardChain(Handle, NextClipHwnd);
    41   //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口
    42   SendMessage(NextClipHwnd, WM_CHANGECBCHAIN, Handle, NextClipHwnd);
    43 end;
    44 
    45 procedure TForm1.FormCreate(Sender: TObject);
    46 begin
    47   //获得观察链中下一个窗口句柄
    48   NextClipHwnd := SetClipBoardViewer(Handle);
    49 end;
    50 
    51 procedure TForm1.ListBox1Click(Sender: TObject);
    52 begin
    53   if ListBox1.Items.Count >= 0 then          
    54     if ListBox1.Items.Strings[ListBox1.ItemIndex]  ='Bitmap'  then
    55       begin
    56         Clipboard.Open;
    57         Clipboard.Clear;
    58         Clipboard.SetAsHandle(CF_BITMAP, Image1.Picture.Bitmap.Handle);
    59         Clipboard.Close;
    60       end
    61     else
    62     begin
    63       Clipboard.Open;
    64       ClipBoard.Clear;
    65       Clipboard.AsText := ListBox1.Items.Strings[ListBox1.ItemIndex];
    66       ClipBoard.Close;
    67     end;
    68 end;
    69 
    70 procedure TForm1.WMDrawClipBoard(var AMessage: TMessage);
    71 begin
    72   //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口
    73   if NextClipHwnd <> 0 then
    74     SendMessage(NextClipHwnd, AMessage.Msg, AMessage.WParam, AMessage.LParam);
    75   //处理剪贴板中内容
    76   if Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_OEMTEXT) then
    77   begin
    78     //查询剪贴板中特定格式的数据内容
    79     ListBox1.Items.Add(Clipboard.asText + '...');
    80   end;
    81   if Clipboard.HasFormat(CF_BITMAP) then
    82   begin
    83     ListBox1.Items.Add('Bitmap');
    84     Image1.Picture.Bitmap.LoadFromClipboardFormat(CF_BITMAP, clipboard.GetAsHandle(CF_BITMAP), 0);
    85   end;
    86 end;
    87 
    88 end.
  • 相关阅读:
    【Others】2048逻辑整理
    【MySQL】MySQL学习笔记(一)
    【PHP】对TP中session的理解
    【Python基础】python 作用域
    【phantomJs + selenium】动态cookie,数据采集记录
    [ZJOI2015][LOJ2137]诸神眷顾的幻想乡(广义SAM)
    [CF235C]Cyclical Quest(SAM)
    [BZOJ1426]收集邮票(概率期望dp)
    [HDU5421]Victor and String(PAM)
    [CF932G]Palindrome Partition(PAM回文划分dp)
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/5500482.html
Copyright © 2020-2023  润新知