會針對資料夾設定 Picture 所指定的自訂圖示。
語法
表情。SetCustomIcon (圖片)
詞 一個代表 資料夾 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Picture | 必要 | IPictureDisp | 會指定資料夾的自訂圖示。 |
註解
Picture 指定的 IPictureDisp 物件的 Type 屬性必須等於 PICTYPE_ICON 或 PICTYPE_BITMAP。 圖示或點陣圖資源的最大大小可為 32x32。 也支援 16x16 或 24x24 的圖示,Microsoft Outlook 在高 DPI) 模式下,可以放大 16x16 圖示 ( 其他尺寸的圖示會導致 SetCustomIcon 回傳錯誤。
你可以為搜尋資料夾以及所有不代表預設或特殊資料夾的資料夾設定自訂圖示。 如果你嘗試為屬於以下資料夾群組的資料夾設定自訂圖示, SetCustomIcon 會回傳錯誤訊息:
- 預設資料夾 (依照 OlDefaultFolders 列舉)
- 特殊資料夾 (依 據 OlSpecialFolders 列舉)
- Exchange 公用資料夾
- 任何 Exchange 信箱的根資料夾
- 隱藏的資料夾
您只能從以 Outlook 同處理序執行的程式碼呼叫 SetCustomIcon。 IPictureDisp 物件無法跨處理序邊界進行封送處理。 如果您嘗試從跨處理序程式碼呼叫 SetCustomIcon,則會發生例外。
此方法提供的自訂資料夾圖示過了執行中的 Outlook 工作階段之後便不會保留。 因此,增益集必須在 Outlook 每次啟動時,設定自訂資料夾圖示。
自訂資料夾圖示不會出現於其他 Exchange 用戶端 (例如 Outlook Web Access) 中,也不會出現於 Windows Mobile 裝置上執行的 Outlook 中。
範例
The following managed code is written in C#. To run a .NET Framework managed code sample that needs to call into a Component Object Model (COM), you must use an interop assembly that defines and maps managed interfaces to the COM objects in the object model type library. For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). Before you run managed code samples for Outlook 2013, ensure that you have installed the Outlook 2013 PIA and have added a reference to the Microsoft Outlook 15.0 Object Library component in Visual Studio. 你應該在 Outlook 外掛類別中使用以下程式碼 ThisAddIn , (使用 Office 開發者工具 for Visual Studio) 。 程式碼中的應用程式物件必須是由 ThisAddIn.Globals提供 的受信任 Outlook 應用程式物件。 欲了解更多使用 Outlook PIA 開發受管理 Outlook 解決方案的資訊,請參閱 MSDN 上的 「歡迎至 Outlook 主要互操作組合參照 」。
下列的 C# 程式碼片段會針對在 [解決方案] 模組中出現的資料夾設定圖示。 程式碼片段依據下文所示的類別而定 PictureDispConverter 。
//Get the icons for the solution
stdole.StdPicture rootPict =
PictureDispConverter.ToIPictureDisp(
Properties.Resources.BRIDGE)
as stdole.StdPicture;
stdole.StdPicture calPict =
PictureDispConverter.ToIPictureDisp(
Properties.Resources.umbrella)
as stdole.StdPicture;
stdole.StdPicture contactsPict =
PictureDispConverter.ToIPictureDisp(
Properties.Resources.group)
as stdole.StdPicture;
stdole.StdPicture tasksPict =
PictureDispConverter.ToIPictureDisp(
Properties.Resources.SUN)
as stdole.StdPicture;
//Set the icons for solution folders
solutionRoot.SetCustomIcon(rootPict);
solutionCalendar.SetCustomIcon(calPict);
solutionContacts.SetCustomIcon(contactsPict);
solutionTasks.SetCustomIcon(tasksPict);
以下是該 PictureDispConverter 類別的定義。
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public static class PictureDispConverter
{
//IPictureDisp GUID.
public static Guid iPictureDispGuid = typeof(stdole.IPictureDisp).GUID;
// Converts an Icon into an IPictureDisp.
public static stdole.IPictureDisp ToIPictureDisp(Icon icon)
{
PICTDESC.Icon pictIcon = new PICTDESC.Icon(icon);
return PictureDispConverter.OleCreatePictureIndirect(pictIcon, ref iPictureDispGuid, true);
}
// Converts an image into an IPictureDisp.
public static stdole.IPictureDisp ToIPictureDisp(Image image)
{
Bitmap bitmap = (image is Bitmap) ? (Bitmap)image : new Bitmap(image);
PICTDESC.Bitmap pictBit = new PICTDESC.Bitmap(bitmap);
return PictureDispConverter.OleCreatePictureIndirect(pictBit, ref iPictureDispGuid, true);
}
[DllImport("OleAut32.dll", EntryPoint = "OleCreatePictureIndirect", ExactSpelling = true,
PreserveSig = false)]
private static extern stdole.IPictureDisp OleCreatePictureIndirect(
[MarshalAs(UnmanagedType.AsAny)] object picdesc, ref Guid iid, bool fOwn);
private readonly static HandleCollector handleCollector =
new HandleCollector("Icon handles", 1000);
// WINFORMS COMMENT:
// PICTDESC is a union in native, so we'll just
// define different ones for the different types
// the "unused" fields are there to make it the right
// size, since the struct in native is as big as the biggest
// union.
private static class PICTDESC
{
//Picture Types
public const short PICTYPE_UNINITIALIZED = -1;
public const short PICTYPE_NONE = 0;
public const short PICTYPE_BITMAP = 1;
public const short PICTYPE_METAFILE = 2;
public const short PICTYPE_ICON = 3;
public const short PICTYPE_ENHMETAFILE = 4;
[StructLayout(LayoutKind.Sequential)]
public class Icon
{
internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Icon));
internal int picType = PICTDESC.PICTYPE_ICON;
internal IntPtr hicon = IntPtr.Zero;
internal int unused1 = 0;
internal int unused2 = 0;
internal Icon(System.Drawing.Icon icon)
{
this.hicon = icon.ToBitmap().GetHicon();
}
}
[StructLayout(LayoutKind.Sequential)]
public class Bitmap
{
internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Bitmap));
internal int picType = PICTDESC.PICTYPE_BITMAP;
internal IntPtr hbitmap = IntPtr.Zero;
internal IntPtr hpal = IntPtr.Zero;
internal int unused = 0;
internal Bitmap(System.Drawing.Bitmap bitmap)
{
this.hbitmap = bitmap.GetHbitmap();
}
}
}
}
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。