Couple of quick Questions

rifter1818

Well-known member
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
1) How do i get the icon Assosiated with Folders and "Special things"(My Computer, My Network Places, Recycle Bin etc)...
Currently im using the following code to get Icons (and extra info) for files.
C#:
	[StructLayout(LayoutKind.Sequential)]
	public struct SHFILEINFO 
	 {
		 public IntPtr hIcon;
		 public IntPtr iIcon;
		 public uint dwAttributes;
		 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
		 public string szDisplayName;
		 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
		 public string szTypeName;
	};
	class Win32
	{
		public const uint SHGFI_ICON = 0x100;
		public const uint SHGFI_LARGEICON = 0x0;    // Large icon
		public const uint SHGFI_SMALLICON = 0x1;    // Small icon

		[DllImport("shell32.dll")]
		public static extern IntPtr SHGetFileInfo(string pszPath,
			uint dwFileAttributes,
			ref SHFILEINFO psfi,
			uint cbSizeFileInfo,
			uint uFlags);
	};
//......
IntPtr iconhandle;
iconhandle = Win32.SHGetFileInfo(FileName,0,ref shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_ICON|Win32.SHGFI_LARGEICON);
//....
icon.Image = Icon.FromHandle(shinfo.hIcon).ToBitmap();
I assume this will not work if i sart plugging in directories under filenames...
2) What is the path of the current Desktop..
foreach(string S in System.io.Directory.getfiles(???????))
3) What do things like My Computer and Recycle Bin fall under for System.IO.Directory.getfiles(),System.IO.Directory.getdirectories()...
 
rifter1818 said:
1) How do i get the icon Assosiated with Folders and "Special things"(My Computer, My Network Places, Recycle Bin etc)...
Currently im using the following code to get Icons (and extra info) for files.
I assume this will not work if i sart plugging in directories under filenames...
2) What is the path of the current Desktop..
foreach(string S in System.io.Directory.getfiles(???????))
3) What do things like My Computer and Recycle Bin fall under for System.IO.Directory.getfiles(),System.IO.Directory.getdirectories()...

Im not sure about how to get the Icons but, to get to the folders (in VB at least, I think its pretty much the same in C#...) you can use this:
Code:
Environment.SpecialFolder.[the special folder]
The Windows folders (My Documents, Desktop, My Pictures, etc...) are in an enumeration so the intellisense should kick in at that point and you can just pick the folder youre looking for. Hope that helps...
 
Back
Top