1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Runtime.InteropServices;
6
7 namespace Microsoft.Win32
8 {
9 public class Shell32
10 {
11 public const int MAX_PATH = 256;
12 [StructLayout(LayoutKind.Sequential)]
13 public struct SHITEMID
14 {
15 public ushort cb;
16 [MarshalAs(UnmanagedType.LPArray)]
17 public byte[] abID;
18 }
19
20 [StructLayout(LayoutKind.Sequential)]
21 public struct ITEMIDLIST
22 {
23 public SHITEMID mkid;
24 }
25
26 [StructLayout(LayoutKind.Sequential)]
27 public struct BROWSEINFO
28 {
29 public IntPtr hwndOwner;
30 public IntPtr pidlRoot;
31 public IntPtr pszDisplayName;
32 [MarshalAs(UnmanagedType.LPTStr)]
33 public string lpszTitle;
34 public uint ulFlags;
35 public IntPtr lpfn;
36 public int lParam;
37 public IntPtr iImage;
38 }
39
40 // Browsing for directory.
41 public const uint BIF_RETURNONLYFSDIRS = 0x0001;
42 public const uint BIF_DONTGOBELOWDOMAIN = 0x0002;
43 public const uint BIF_STATUSTEXT = 0x0004;
44 public const uint BIF_RETURNFSANCESTORS = 0x0008;
45 public const uint BIF_EDITBOX = 0x0010;
46 public const uint BIF_VALIDATE = 0x0020;
47 public const uint BIF_NEWDIALOGSTYLE = 0x0040;
48 public const uint BIF_USENEWUI = (BIF_NEWDIALOGSTYLE | BIF_EDITBOX);
49 public const uint BIF_BROWSEINCLUDEURLS = 0x0080;
50 public const uint BIF_BROWSEFORCOMPUTER = 0x1000;
51 public const uint BIF_BROWSEFORPRINTER = 0x2000;
52 public const uint BIF_BROWSEINCLUDEFILES = 0x4000;
53 public const uint BIF_SHAREABLE = 0x8000;
54
55 [StructLayout(LayoutKind.Sequential)]
56 public struct SHFILEINFO
57 {
58 public const int NAMESIZE = 80;
59 public IntPtr hIcon;
60 public int iIcon;
61 public uint dwAttributes;
62 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
63 public string szDisplayName;
64 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)]
65 public string szTypeName;
66 };
67
68 public const uint SHGFI_ICON = 0x000000100; // get icon
69 public const uint SHGFI_DISPLAYNAME = 0x000000200; // get display name
70 public const uint SHGFI_TYPENAME = 0x000000400; // get type name
71 public const uint SHGFI_ATTRIBUTES = 0x000000800; // get attributes
72 public const uint SHGFI_ICONLOCATION = 0x000001000; // get icon location
73 public const uint SHGFI_EXETYPE = 0x000002000; // return exe type
74 public const uint SHGFI_SYSICONINDEX = 0x000004000; // get system icon index
75 public const uint SHGFI_LINKOVERLAY = 0x000008000; // put a link overlay on icon
76 public const uint SHGFI_SELECTED = 0x000010000; // show icon in selected state
77 public const uint SHGFI_ATTR_SPECIFIED = 0x000020000; // get only specified attributes
78 public const uint SHGFI_LARGEICON = 0x000000000; // get large icon
79 public const uint SHGFI_SMALLICON = 0x000000001; // get small icon
80 public const uint SHGFI_OPENICON = 0x000000002; // get open icon
81 public const uint SHGFI_SHELLICONSIZE = 0x000000004; // get shell size icon
82 public const uint SHGFI_PIDL = 0x000000008; // pszPath is a pidl
83 public const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute
84 public const uint SHGFI_ADDOVERLAYS = 0x000000020; // apply the appropriate overlays
85 public const uint SHGFI_OVERLAYINDEX = 0x000000040; // Get the index of the overlay
86
87 public const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
88 public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
89
90 [DllImport("Shell32.dll")]
91 public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
92
93 [DllImport("shell32.dll", ExactSpelling = true)]
94 public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, uint cidl, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl, uint dwFlags);
95
96 }
97 }