我想在代码中使用剪贴板处理数据,使用前需要判断一下剪贴板是否有数据,有的话,保存一下,然后再恢复剪贴板的数据;如果剪贴板没有数据,则使用完了剪贴板后情况剪贴板。不知是否可以实现?

解决方案 »

  1.   

    DELPHI中的编辑控件(如:Edit,Memo,RichEdit等)都有剪贴板操作过程。如:
    procedure TMainForm.EditCut(Sender: TObject);
    begin
      Editor.CutToClipboard;
    end;procedure TMainForm.EditCopy(Sender: TObject);
    begin
      Editor.CopyToClipboard;
    end;procedure TMainForm.EditPaste(Sender: TObject);
    begin
      Editor.PasteFromClipboard;
    end;
    上述是RichEdit操作剪贴板的操作语句。
    另外DELPHI有专门一个单元:Clipbrd,引用这个单元后,就可以在代码中操作剪贴板。下面是DELPHI说明示例:
    The following code locks the memory for text on the Clipboard, then reads the text.var  MyHandle: THandle;
      TextPtr: PChar;
      MyString: string;
    begin
      ClipBoard.Open;
    try
      MyHandle := Clipboard.GetAsHandle(CF_TEXT);
      TextPtr := GlobalLock(MyHandle);
      MyString := StrPas(TextPtr);
      GlobalUnlock(MyHandle);
    finally
      Clipboard.Close;
    end;
    end;
      

  2.   

    uses Clipbrd;procedure TForm1.Button1Click(Sender: TObject);
    var
      Abmp:Tbitmap;
    begin
      Image1.Picture.Metafile.Assign(ClipBoard);
      Abmp := Tbitmap.Create;
      Abmp.Height:=Image1.Picture.Metafile.Height;
      Abmp.Width:=Image1.Picture.Metafile.Width;
      Abmp.Canvas.Draw(0,0,Image1.Picture.Metafile);
      Abmp.SaveToFile ('c:\abcd.bmp');
      Abmp.free;
    end;
      

  3.   

    有办法:
    http://topic.csdn.net/u/20110911/13/6aa14ed1-823a-40a6-9188-7e70639b61a2.html