C
ChJK
Unregistered / Unconfirmed
GUEST, unregistred user!
我上次在本站贴出了一份"剪贴板备份恢复"文章,最近发现存在bug,想请大家帮忙解决一下,先把部分代码重新贴出来,以便大家指点.
procedure CopyStreamToClipboard(fmt: cardinal; S: TMemoryStream);{将数据流恢复到剪贴板,我发现不能将cf_bitmap即Bitmap格式,恢复到剪贴板,请求大家帮助}
var
hMem: THandle;
pMem: Pointer;
begin
S.Position := 0;
hMem := GlobalAlloc(GMEM_MOVEABLE 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
SetClipboardData(fmt, hmem);
{我最初用Clipboard.SetAsHandle(fmt, hMem)写的,但效果不好,不知如何改正}
finally
Clipboard.Close;
end;
end
else
begin
GlobalFree(hMem);
OutOfMemoryError;
end;
end
else
OutOfMemoryError;
end;
procedure CopyStreamFromClipboard(fmt: cardinal; S: TMemoryStream);{将剪贴板的数据保存到数据流中,同样不能将cf_bitmap和cf_enhmetafile格式保存为数据流,请求大家帮助}
var
hMem: THandle;
pMem: Pointer;
begin
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
else
raise Exception.Create('CopyStreamFromClipboard: could not lock global handle ' + 'obtained from clipboard!');//对出现的异常进行处理
end;
end;
这是我在备份"画图"程序中图象时发现的错误,由于积分有限,请见谅
procedure CopyStreamToClipboard(fmt: cardinal; S: TMemoryStream);{将数据流恢复到剪贴板,我发现不能将cf_bitmap即Bitmap格式,恢复到剪贴板,请求大家帮助}
var
hMem: THandle;
pMem: Pointer;
begin
S.Position := 0;
hMem := GlobalAlloc(GMEM_MOVEABLE 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
SetClipboardData(fmt, hmem);
{我最初用Clipboard.SetAsHandle(fmt, hMem)写的,但效果不好,不知如何改正}
finally
Clipboard.Close;
end;
end
else
begin
GlobalFree(hMem);
OutOfMemoryError;
end;
end
else
OutOfMemoryError;
end;
procedure CopyStreamFromClipboard(fmt: cardinal; S: TMemoryStream);{将剪贴板的数据保存到数据流中,同样不能将cf_bitmap和cf_enhmetafile格式保存为数据流,请求大家帮助}
var
hMem: THandle;
pMem: Pointer;
begin
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
else
raise Exception.Create('CopyStreamFromClipboard: could not lock global handle ' + 'obtained from clipboard!');//对出现的异常进行处理
end;
end;
这是我在备份"画图"程序中图象时发现的错误,由于积分有限,请见谅