我正在尝试使用剪贴板 API(在 Delphi 中)从 Word 文档中提取图像。我的代码在 Windows XP/2003 中工作正常,但在 Windows 2008 64 位中它不起作用。在 win 2008 中,我收到一条错误消息,提示 Clipboard.Formats 为空且不包含任何格式。
图像似乎被复制到剪贴板(我可以通过 Word 在剪贴板中看到它)但是当我尝试询问剪贴板他有什么格式时,它说它没有任何格式。
如何在 win 2008/Vista 上以编程方式访问剪贴板?根据我对 2008 64 位的了解,这可能是一个安全问题......
这是代码片段:
这就是我尝试将图像复制到剪贴板的方式:
W.ActiveDocument.InlineShapes.Item(1).Select; // W is a word ole object
W.Selection.Copy;
这就是我尝试粘贴它的方式。
Clipboard.Open;
Write2DebugFile('FormatCount = ' + IntToStr(Clipboard.FormatCount)); // FormatCount=0
For JJ := 1 to Clipboard.FormatCount Do
Write2DebugFile('#'+ IntToStr(JJ) + ':' + IntToStr(Clipboard.Formats[JJ]));
If (Clipboard.HasFormat(CF_BITMAP)) or
(Clipboard.HasFormat(CF_PICTURE)) or
(Clipboard.HasFormat(CF_METAFILEPICT)) then // all HasFormat calls returns false.
Begin
Jpeg := TJPEGImage.Create;
Bitmap := TBitmap.Create;
Bitmap.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
Jpeg.Assign(Bitmap);
Jpeg.SaveToFile(JpgFileN);
try Jpeg.Free; except; end;
ResizeImage(JpgFileN,750);
Write2DebugFile('Saving ' + JpgFileN);
End
else Write2DebugFile('Doesnt have the right format');
提前致谢, Itay