Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.


[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()...

Posted
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()...

 

I'm not sure about how to get the Icons but, to get to the folders (in VB at least, I think it's pretty much the same in C#...) you can use this:

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 you're looking for. Hope that helps...

Being smarter than you look is always better than looking smarter than you are.
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...