剪贴板的流存储

时间:2010-01-27 09:04:33  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:ypeTDataIdnet = array[0..2] of Char;TClipboardFileHead = packed recordrIdent: TDataIdnet;rCount: Word;end;TClipboardFileItem = packed recordrFormat: Word;rSize: Longword;rData: Pointer;end;const rDataIdnet: TDataIdnet = 'cbf';function ClipboardSaveToStream(mStream: TStr...
  正文:

(*//
标题:剪贴板的流存储
说明:如果你想借用剪贴板,有这套函数就方便了
设计:Zswang
日期:2003-11-14
支持:wjhu111@21cn.com
//*)

///////Begin Source
uses Clipbrd;

type
TDataIdnet = array[0..2] of Char;
TClipboardFileHead = packed record
rIdent: TDataIdnet;
rCount: word;
end;

TClipboardFileItem = packed record
rFormat: Word;
rSize: Longword;
rData: Pointer;
end;

const rDataIdnet: TDataIdnet = 'cbf';

function ClipboardSaveToStream(mStream: TStream): Boolean;
var
vClipboardFileHead: TClipboardFileHead;
vClipboardFileItem: TClipboardFileItem;
I: Integer;
vData: THandle;
begin
  Result := False;
  if not Assigned(mStream) then Exit;
  vClipboardFileHead.rIdent := rDataIdnet;
  vClipboardFileHead.rCount := Clipboard.FormatCount;
  mStream.Write(vClipboardFileHead, SizeOf(vClipboardFileHead));
  try
    Clipboard.Open;
    for I := 0 to Clipboard.FormatCount - 1 do begin
      vData := GetClipboardData(Clipboard.Formats[I]);
      vClipboardFileItem.rFormat := Clipboard.Formats[I];
      vClipboardFileItem.rSize := GlobalSize(vData);
      vClipboardFileItem.rData := GlobalLock(vData);
      try
        mStream.Write(vClipboardFileItem, SizeOf(vClipboardFileItem) -
        SizeOf(vClipboardFileItem.rData));
        mStream.Write(vClipboardFileItem.rData^, vClipboardFileItem.rSize);
        finally
          GlobalUnlock(vData);
        end;
      end;
      finally
        Clipboard.Close;
      end;
      Result := True;
    end; { ClipboardSaveToStream }
    
    function ClipboardLoadFromStream(mStream: TStream): Boolean;
    var
    vClipboardFileHead: TClipboardFileHead;
    vClipboardFileItem: TClipboardFileItem;
    I: Integer;
    vData: THandle;
    begin
      Result := False;
      if not Assigned(mStream) then Exit;
      if mStream.Size <= SizeOf(vClipboardFileHead) then Exit;
      mStream.Read(vClipboardFileHead, SizeOf(vClipboardFileHead));
      if vClipboardFileHead.rIdent <> rDataIdnet then Exit;
      Clipboard.Clear;
      Clipboard.Open;
      try
        for I := 0 to vClipboardFileHead.rCount - 1 do begin
          mStream.Read(vClipboardFileItem, SizeOf(vClipboardFileItem) -
          SizeOf(vClipboardFileItem.rData));
          vData := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE,
          vClipboardFileItem.rSize);

剪贴板的流存储》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/2010-01-27/12466.html


关键字:

关于《剪贴板的流存储》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td