剪切板内容如何保存到内存流?(100)

  • 主题发起人 主题发起人 qutwah
  • 开始时间 开始时间
Q

qutwah

Unregistered / Unconfirmed
GUEST, unregistred user!
我在全文检索中看到如下代码,但在我机器上不能执行.每次执行CopyStreamFromClipboard时,都产生异常(raise Exception.Create( 'CopyStreamFromClipboard: could not lock global handle '+ 'obtained from clipboard!');),不知是什么原因,各位高手能帮忙看看吗?Procedure CopyStreamToClipboard( fmt: Cardinal; S: TStream ); Var hMem: THandle; pMem: Pointer; Begin S.Position := 0; hMem := GlobalAlloc( GHND or GMEM_DDESHARE, S.Size ); If hMem <> 0 Then Begin pMem := GlobalLock( hMem ); If pMem <> Nil Then Begin S.Read( pMem^, S.Size ); S.Position := 0; GlobalUnlock( hMem ); 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 hMem := Clipboard.GetAsHandle( fmt ); If hMem <> 0 Then Begin pMem := GlobalLock( hMem ); If pMem <> Nil Then Begin S.Write( pMem^, GlobalSize( hMem )); S.Position := 0; GlobalUnlock( hMem ); End { If } Else raise Exception.Create( 'CopyStreamFromClipboard: could not lock global handle '+ 'obtained from clipboard!'); End; { If } End; { CopyStreamFromClipboard }
 
你的调用在哪里呢?贴出来看看
 
fmt 这个是从哪里来的?你搜一下delphi的帮助clipboard.getashandle里面有一个详细的例子
 
后退
顶部