将剪贴板复制到流和恢复的DELPHI代码

时间:2010-01-26 12:53:29  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:rd(fmt: Cardinal; S: TStream);varhMem: THandle;pMem: Pointer;begin  Assert(Assigned(S));  S.Position := 0;  hMem := GlobalAlloc(GHND or GMEM_DDESHARE, S.Size);  if hMem <> 0 then  begin    pMem := GlobalLock(hMem);&nbs...
  正文:

请看下面的代码


uses clipbrd;

procedure CopyStreamToClipboard(fmt: Cardinal; S: TStream);
var
hMem: THandle;
pMem: Pointer;
begin
  Assert(Assigned(S));
  S.Position := 0;
  hMem := GlobalAlloc(GHND or GMEM_DDESHARE, S.Size);
  if hMem <> 0 then
  begin
    pMem := GlobalLock(hMem);
    if pMem <> nil then
    begin
      try
        S.Read(pMem^, S.Size);
        S.Position := 0;
        finally
          GlobalUnlock(hMem);
        end;
        Clipboard.Open;
        try
          Clipboard.SetAsHandle(fmt, hMem);
          finally
            Clipboard.Close;
          end;
        end { If }
        else
        begin
          GlobalFree(hMem);
          OutOfMemoryError;
        end;
      end { If }
      else
      OutOfMemoryError;
    end; { CopyStreamToClipboard }
    
    procedure CopyStreamFromClipboard(fmt: Cardinal; S: TStream);
    var
    hMem: THandle;
    pMem: Pointer;
    begin
      Assert(Assigned(S));
      hMem := Clipboard.GetAsHandle(fmt);
      if hMem <> 0 then
      begin
        pMem := GlobalLock(hMem);
        if pMem <> nil then
        begin
          try
            S.Write(pMem^, GlobalSize(hMem));
            S.Position := 0;
            finally
              GlobalUnlock(hMem);
            end;
          end { If }
          else
          raise Exception.Create(‘CopyStreamFromClipboard: could not lock global handle ‘ +
          ‘obtained from clipboard!‘);
        end; { If }
      end; { CopyStreamFromClipboard }
"将剪贴板复制到流和恢复的DELPHI代码"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12423.html

 1/4    1 2 3 4 下一页 尾页


关键字:

关于《将剪贴板复制到流和恢复的DELPHI代码》文章的评论

站内搜索: 高级搜索

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