2 // Copyright (c) 2010-2014 Yves Langisch. All rights reserved.
3 // http://cyberduck.ch/
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // Bug fixes, suggestions and comments should be sent to:
20 using System
.Runtime
.InteropServices
;
22 namespace Ch
.Cyberduck
.Core
25 /// Wraps necessary Shell32.dll structures and functions required to retrieve Icon Handles using SHGetFileInfo. Code
26 /// courtesy of MSDN Cold Rooster Consulting case study.
29 // This code has been left largely untouched from that in the CRC example. The main changes have been moving
30 // the icon reading code over to the IconReader type.
33 public const uint BIF_BROWSEFORCOMPUTER
= 0x1000;
34 public const uint BIF_BROWSEFORPRINTER
= 0x2000;
35 public const uint BIF_BROWSEINCLUDEFILES
= 0x4000;
36 public const uint BIF_BROWSEINCLUDEURLS
= 0x0080;
37 public const uint BIF_DONTGOBELOWDOMAIN
= 0x0002;
38 public const uint BIF_EDITBOX
= 0x0010;
39 public const uint BIF_NEWDIALOGSTYLE
= 0x0040;
40 public const uint BIF_RETURNFSANCESTORS
= 0x0008;
41 public const uint BIF_RETURNONLYFSDIRS
= 0x0001;
42 public const uint BIF_SHAREABLE
= 0x8000;
43 public const uint BIF_STATUSTEXT
= 0x0004;
44 public const uint BIF_USENEWUI
= (BIF_NEWDIALOGSTYLE
| BIF_EDITBOX
);
45 public const uint BIF_VALIDATE
= 0x0020;
46 public const uint FILE_ATTRIBUTE_DIRECTORY
= 0x00000010;
47 public const uint FILE_ATTRIBUTE_NORMAL
= 0x00000080;
48 public const int MAX_PATH
= 256;
49 public const uint SHGFI_ADDOVERLAYS
= 0x000000020; // apply the appropriate overlays
51 public const uint SHGFI_ATTRIBUTES
= 0x000000800; // get attributes
52 public const uint SHGFI_ATTR_SPECIFIED
= 0x000020000; // get only specified attributes
53 public const uint SHGFI_DISPLAYNAME
= 0x000000200; // get display name
54 public const uint SHGFI_EXETYPE
= 0x000002000; // return exe type
55 public const uint SHGFI_ICON
= 0x000000100; // get icon
56 public const uint SHGFI_ICONLOCATION
= 0x000001000; // get icon location
57 public const uint SHGFI_LARGEICON
= 0x000000000; // get large icon
58 public const uint SHGFI_LINKOVERLAY
= 0x000008000; // put a link overlay on icon
59 public const uint SHGFI_OPENICON
= 0x000000002; // get open icon
60 public const uint SHGFI_OVERLAYINDEX
= 0x000000040; // Get the index of the overlay
61 public const uint SHGFI_PIDL
= 0x000000008; // pszPath is a pidl
62 public const uint SHGFI_SELECTED
= 0x000010000; // show icon in selected state
63 public const uint SHGFI_SHELLICONSIZE
= 0x000000004; // get shell size icon
64 public const uint SHGFI_SMALLICON
= 0x000000001; // get small icon
65 public const uint SHGFI_SYSICONINDEX
= 0x000004000; // get system icon index
66 public const uint SHGFI_TYPENAME
= 0x000000400; // get type name
67 public const uint SHGFI_USEFILEATTRIBUTES
= 0x000000010; // use passed dwFileAttribute
69 [DllImport("shell32.dll", CharSet
= CharSet
.Auto
)]
70 public static extern IntPtr
SHGetFileInfo(string pszPath
, uint dwFileAttributes
, ref SHFILEINFO psfi
,
71 uint cbFileInfo
, uint uFlags
);
73 [StructLayout(LayoutKind
.Sequential
)]
74 public struct BROWSEINFO
76 public IntPtr hwndOwner
;
77 public IntPtr pidlRoot
;
78 public IntPtr pszDisplayName
;
79 [MarshalAs(UnmanagedType
.LPTStr
)] public string lpszTitle
;
86 [StructLayout(LayoutKind
.Sequential
)]
87 public struct ITEMIDLIST
92 [StructLayout(LayoutKind
.Sequential
, CharSet
= CharSet
.Auto
)]
93 public struct SHFILEINFO
97 public uint dwAttributes
;
98 [MarshalAs(UnmanagedType
.ByValTStr
, SizeConst
= 260)] public string szDisplayName
;
99 [MarshalAs(UnmanagedType
.ByValTStr
, SizeConst
= 80)] public string szTypeName
;
102 [StructLayout(LayoutKind
.Sequential
)]
103 public struct SHITEMID
106 [MarshalAs(UnmanagedType
.LPArray
)] public byte[] abID
;
111 /// Wraps necessary functions imported from User32.dll. Code courtesy of MSDN Cold Rooster Consulting example.
116 /// Provides access to function required to delete handle. This method is used internally
117 /// and is not required to be called separately.
119 /// <param name="hIcon">Pointer to icon handle.</param>
120 /// <returns>N/A</returns>
121 [DllImport("User32.dll")]
122 public static extern int DestroyIcon(IntPtr hIcon
);