VSTO SetCustomIcon Outlook文件夹 [英] VSTO SetCustomIcon Outlook Folder

查看:118
本文介绍了VSTO SetCustomIcon Outlook文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VSTO Add In,即如果该文件夹尚未存在,则会在启动时的Outlook存储中创建自定义文件夹。我想为该文件夹设置自定义图标。我在链接中找到了下面的示例,在尝试
转换为VB.net后,它无法正常工作。我遇到的一个问题是(TypeOf图像是Bitmap)和New Bitmap(图像)。这些行上有语法错误,我不知道如何处理这些错误。

我可以单步执行代码,但它在Return PictureDispConverter行上死掉。 Outlook只是关闭。我缺少什么?

I can step through the code, but it dies on the Return PictureDispConverter line. Outlook simply closes. What am I missing?

        Public Overloads Shared Function ToIPictureDisp(ByVal image As Image) As stdole.IPictureDisp
            Dim bitmap As Bitmap = CType(image, Bitmap)
        'TODO: Warning!!!, inline IF is not supported ?
        (TypeOf image Is Bitmap)
        New Bitmap(image)
        Dim pictBit As PICTDESC.Bitmap = New PICTDESC.Bitmap(bitmap)
            Return PictureDispConverter.OleCreatePictureIndirect(pictBit, iPictureDispGuid, True)
        End Function

https://msdn.microsoft.com/en-us/VBA / Outlook-VBA / articles / folder-setcustomicon-method-outlook

https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/folder-setcustomicon-method-outlook

推荐答案

您好,

尝试使用以下代码:

   Public Overloads Shared Function ToIPictureDisp(ByVal image As Image) As stdole.IPictureDisp
            Dim bitmap As Bitmap = New Bitmap(image)
        Dim pictBit As PICTDESC.Bitmap = New PICTDESC.Bitmap(bitmap)
            Return PictureDispConverter.OleCreatePictureIndirect(pictBit, iPictureDispGuid, True)
        End Function




您可以设置自定义图标r搜索文件夹以及不代表默认文件夹或特殊文件夹的所有文件夹。如果您尝试为属于以下文件夹组之一的文件夹设置自定义图标, 
SetCustomIcon 将返回错误:

  • Default folders (as listed by the OlDefaultFolders enumeration)

特殊文件夹(由  <列出strong style ="font-weight:700">
OlSpecialFolders 枚举)

Special folders (as listed by the  OlSpecialFolders enumeration)

交换公共文件夹

任何Exchange ma的根文件夹ilbox

Root folder of any Exchange mailbox

隐藏文件夹

您只能致电  SetCustomIcon 来自在进程中作为Outlook运行的代码。
IPictureDisp 对象无法跨进程边界进行编组。如果您尝试从进程外代码中调用
SetCustomIcon ,则会发生异常。有关详细信息,请参阅自动化
服务器无法跨进程边界传递指向图片对象的IPictureDisp实现的指针

You can only call  SetCustomIcon from code that runs in-process as Outlook. An IPictureDisp object cannot be marshaled across process boundaries. If you attempt to call SetCustomIcon from out-of-process code, an exception will occur. For more details, seeAn automation server cannot pass a pointer to the picture object's IPictureDisp implementation across process boundaries.

您可以阅读更多相关内容并在VB.NET中查找示例代码在
如何:在导航窗格
文章中为Outlook文件夹设置自定义图标。

You can read more about that and find a sample code in VB.NET in the How To: Set a custom icon for an Outlook folder in the Navigation Pane article.


这篇关于VSTO SetCustomIcon Outlook文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆