Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C#

Dual Pane File Manager

Rate me:
Please Sign up or sign in to vote.
4.64/5 (28 votes)
21 Dec 2010CPOL8 min read 140.9K   2.3K   119  
A dual pane file manager for Windows XP.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace JFileManager
{
	class cJDirectoryInfo
	{
		public string DisplayName = "";
		public string Path = "";
		public ObjectType ObjectType = ObjectType.FOLDER;
		public string TypeName = "";
		public int IconIndex = 0;
		public int SelectedIconIndex = 0;
		public long Size = 0L;
		public Image Image = null;
		public DateTime LastWriteTime;
		public string SortName = "";
		public FileAttributes Attributes;

		public cJDirectoryInfo(DirectoryInfo dInfo, bool blnGetImage)
		{
			SHFILEINFO shfi = new SHFILEINFO();

			uint uFlags = (uint)(SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_TYPENAME | SHGFI.SHGFI_ADDOVERLAYS | SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_DISPLAYNAME);
			IntPtr ipTemp = cCommon.SHGetFileInfo(dInfo.FullName.ToString(), 0, out shfi, Marshal.SizeOf(shfi), uFlags);

			this.Path = dInfo.FullName;
			this.SortName = "0" + this.Path;
			this.Image = null;
			this.LastWriteTime = dInfo.LastWriteTime;
			this.Attributes = dInfo.Attributes;

			// Check result
			if (ipTemp != IntPtr.Zero)
			{
				this.DisplayName = shfi.szDisplayName;
				this.TypeName = shfi.szTypeName;
				this.IconIndex = shfi.iIcon;

				if (blnGetImage)
				{
					if (shfi.hIcon != IntPtr.Zero)
					{
						Icon icTemp = Icon.FromHandle(shfi.hIcon);
						IconConverter imConvert = new IconConverter();
						object obTemp = new object();
						Type typ = typeof(Image);
						obTemp = imConvert.ConvertTo(icTemp, typ);
						this.Image = (Image)obTemp;
					}
				}
			}
			else
			{
				this.DisplayName = "";
				this.TypeName = "";
				this.IconIndex = 0;
			}

			if (shfi.hIcon != IntPtr.Zero)
				cCommon.DestroyIcon(shfi.hIcon);

			//	Selected Icon
			uFlags = (uint)(SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_ADDOVERLAYS | SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_OPENICON);
			ipTemp = cCommon.SHGetFileInfo(dInfo.FullName, 0, out shfi, Marshal.SizeOf(shfi), uFlags);

			if (shfi.hIcon != IntPtr.Zero)
				cCommon.DestroyIcon(shfi.hIcon);

			this.SelectedIconIndex = shfi.iIcon;
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Retired
United Kingdom United Kingdom
I have been a keen hobbyist programmer since getting my first computer - a Vic 20 (you had to be able to write programs then since few programs were available and all were expensive).
Retired and now living in Pewsey, Wiltshire, where I spend (far too much of) my time writing computer programs to keep my mind active.

Comments and Discussions