在 .NET 4.0 中将图标转换为 IPicture?

发布于 2024-08-20 14:43:35 字数 499 浏览 4 评论 0原文

标准和(某种程度上)支持的答案之一是使用 Microsoft.VisualBasic.Compatibility 程序集中的 Support.IconToIPicture。但是,在 .NET 4.0 中,“此 API 现已过时”。

是的,有各种解决方案 就在那里,但我认为如果微软废弃了这种方法,就会有另一种“受支持”的替代方法。

One of the standard and (somewhat) supported answers was to use Support.IconToIPicture from the Microsoft.VisualBasic.Compatibility assembly. However, in .NET 4.0, "This API is now obsolete".

Yes, there are various solutions out there, but I would think that if Microsoft was obsoleting this method, there would be another "supported" alternative.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-08-27 14:43:35

我相信,这个API已经过时了,因为IPicture是一个OLE接口。通过使用它,您将进入 Microsoft 不希望您进入的非托管世界。您可以通过调用来重现该行为
IntPtr aHIcon = Icon.GetHicnFromIcon(yourIcon);

然后您需要将此句柄传递给 OleCreatePictureIndirect (代码是 C++ 语言):

PICTDESC aDesc;
aDesc.cbSizeofstruct = sizeof PICTDESC;
aDesc.picType = PICTYPE_ICON;
aDesc.icon.icon = aHIcon;

IPicture * aPict = 0;
OleCreatePictureIndirect(&aDesc, __uuidof(IPicture), TRUE, (void **) &aPict);

唯一的困难 -- 您需要提供用于包装的 COM 互操作代码C++ 结构和函数调用。

I believe, this API is obsolete, because IPicture is an OLE interface. By working with it, you dive into the unmanaged world which Microsoft doesn't want you to. You could reproduce the behavior by calling
IntPtr aHIcon = Icon.GetHicnFromIcon(yourIcon);

Then you need to pass this handle to OleCreatePictureIndirect (the code is in C++):

PICTDESC aDesc;
aDesc.cbSizeofstruct = sizeof PICTDESC;
aDesc.picType = PICTYPE_ICON;
aDesc.icon.icon = aHIcon;

IPicture * aPict = 0;
OleCreatePictureIndirect(&aDesc, __uuidof(IPicture), TRUE, (void **) &aPict);

The only difficulty -- you will need to provide a COM interop code for wrapping the C++ structure and function call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文