Folder.SetCustomIcon メソッド (Outlook)

フォルダーの Picture に指定されたカスタム アイコンを設定します。

構文

SetCustomIcon(Picture)

Folder オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
Picture 必須 IPictureDisp フォルダーのカスタム アイコンを指定します。

注釈

Picture で指定される IPictureDisp オブジェクトの Type プロパティは、PICTYPE_ICONまたはPICTYPE_BITMAPと等しい必要があります。 アイコンまたはビットマップのリソースには、32 x 32 の最大サイズを持つことができます。 アイコン 16 x 16 または 24 x 24 もサポートされており、高のドット/インチ (DPI) モードで Outlook が実行されている場合、 Microsoft Outlookが 16 x 16 のアイコンを拡張できます。 他のサイズのアイコンには、エラーを返すように SetCustomIcon が発生します。

検索フォルダーと、既定または特別なフォルダーを表さないすべてのフォルダーのカスタム アイコンを設定できます。 次のフォルダーのグループのいずれかに属しているフォルダーのカスタム アイコンを設定しようとすると、 SetCustomIcon はエラーを返します。

  • 既定のフォルダー ( OlDefaultFolders 列挙体に一覧表示)
  • 特別なフォルダー ( OlSpecialFolders 列挙体に一覧表示)
  • Exchange のパブリック フォルダー
  • Exchange メールボックスのルート フォルダー
  • 隠しフォルダー

SetCustomIcon は、コードを実行中としては、Outlook からのみ呼び出すことができます。 IPictureDisp オブジェクトは、プロセス境界を越えてマーシャ リングすることはできません。 プロセス外のコードから SetCustomIcon を呼び出すしようとすると、例外が発生します。

このメソッドで設定されるカスタム フォルダー アイコンは、実行中の Outlook セッションの終了後は保持されません。 そのため、Outlook を起動するたびにアドインでカスタム フォルダー アイコンを設定する必要があります。

カスタム フォルダー アイコンは Outlook Web Access などの他の Exchange クライアントに表示されないだけでなく、Windows Mobile デバイス上で実行している Outlook にも表示されません。

次のマネージ コードは C# で作成されています。 コンポーネント オブジェクト モデル (COM) に呼び出す必要がある .NET Framework マネージ コード サンプルを実行するには、マネージ インターフェイスを定義し、オブジェクト モデル タイプ ライブラリの COM オブジェクトにマップする相互運用機能アセンブリを使用する必要があります。 Outlook の場合、Visual Studio および Outlook プライマリ相互運用機能アセンブリ (PIA) を使用できます。 Outlook 2013 用のマネージ コード サンプルを実行する前に、Outlook 2013 PIA をインストールしており、Visual Studio で Microsoft Outlook 15.0 オブジェクト ライブラリ コンポーネントへの参照を追加していることを確認してください。 Outlook アドインのクラスで次のコードを ThisAddIn 使用する必要があります (Office Developer Tools for Visual Studio を使用)。 コードの Application オブジェクトは で提供された、信頼済み Outlook ThisAddIn.Globals オブジェクトである必要があります。 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 のサポートおよびフィードバックを参照してください。