home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Systeme / SyMenu / SyMenu.exe / FolderBrowserDialogEx.cs next >
Text File  |  2011-06-11  |  7KB  |  178 lines

  1. ∩╗┐// FolderBrowserDialogEx.cs
  2. //
  3. // A replacement for the builtin System.Windows.Forms.FolderBrowserDialog class.
  4. // This one includes an edit box, and also displays the full path in the edit box. 
  5. //
  6. // based on code from http://support.microsoft.com/default.aspx?scid=kb;[LN];306285 
  7. // 
  8. // 20 Feb 2009
  9. //
  10. // ========================================================================================
  11. // Example usage:
  12. // 
  13. // string _folderName = "c:\\dinoch";
  14. // private void button1_Click(object sender, EventArgs e)
  15. // {
  16. //     _folderName = (System.IO.Directory.Exists(_folderName)) ? _folderName : "";
  17. //     var dlg1 = new Ionic.Utils.FolderBrowserDialogEx
  18. //     {
  19. //         Description = "Select a folder for the extracted files:",
  20. //         ShowNewFolderButton = true,
  21. //         ShowEditBox = true,
  22. //         //NewStyle = false,
  23. //         SelectedPath = _folderName,
  24. //         ShowFullPathInEditBox= false,
  25. //     };
  26. //     dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;
  27. // 
  28. //     var result = dlg1.ShowDialog();
  29. // 
  30. //     if (result == DialogResult.OK)
  31. //     {
  32. //         _folderName = dlg1.SelectedPath;
  33. //         this.label1.Text = "The folder selected was: ";
  34. //         this.label2.Text = _folderName;
  35. //     }
  36. // }
  37. //
  38.  
  39.  
  40. namespace Ionic.Utils
  41. {
  42. using System;
  43. using System.Windows.Forms;
  44. using System.Runtime.InteropServices;
  45. using System.ComponentModel;
  46. using System.Security.Permissions;
  47. using System.Security;
  48. using System.Threading;
  49.  
  50.     //[Designer("System.Windows.Forms.Design.FolderBrowserDialogDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DefaultEvent("HelpRequest"), SRDescription("DescriptionFolderBrowserDialog"), DefaultProperty("SelectedPath")]
  51.     public class FolderBrowserDialogEx : System.Windows.Forms.CommonDialog
  52.     {
  53.         private static readonly int MAX_PATH = 260;
  54.  
  55.         // Fields
  56.         private PInvoke.BrowseFolderCallbackProc _callback;
  57.         private string _descriptionText;
  58.         private Environment.SpecialFolder _rootFolder;
  59.         private string _selectedPath;
  60.         private bool _selectedPathNeedsCheck;
  61.         private bool _showNewFolderButton;
  62.         private bool _showEditBox;
  63.         private bool _showBothFilesAndFolders;
  64.         private bool _newStyle = true;
  65.         private bool _showFullPathInEditBox = true;
  66.         private bool _dontIncludeNetworkFoldersBelowDomainLevel;
  67.         private int _uiFlags;
  68.         private IntPtr _hwndEdit;
  69.         private IntPtr _rootFolderLocation;
  70.  
  71.         // Events
  72.         //[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  73.         public new event EventHandler HelpRequest
  74.         {
  75.             add
  76.             {
  77.                 base.HelpRequest += value;
  78.             }
  79.             remove
  80.             {
  81.                 base.HelpRequest -= value;
  82.             }
  83.         }
  84.  
  85.         // ctor
  86.         public FolderBrowserDialogEx()
  87.         {
  88.             this.Reset();
  89.         }
  90.  
  91.         // Factory Methods
  92.         public static FolderBrowserDialogEx PrinterBrowser()
  93.         {
  94.             FolderBrowserDialogEx x = new FolderBrowserDialogEx();
  95.         // avoid MBRO comppiler warning when passing _rootFolderLocation as a ref:
  96.         x.BecomePrinterBrowser();
  97.             return x;
  98.         }
  99.  
  100.         public static FolderBrowserDialogEx ComputerBrowser()
  101.         {
  102.             FolderBrowserDialogEx x = new FolderBrowserDialogEx();
  103.         // avoid MBRO comppiler warning when passing _rootFolderLocation as a ref:
  104.         x.BecomeComputerBrowser();
  105.             return x;
  106.         }
  107.  
  108.  
  109.     // Helpers
  110.     private void BecomePrinterBrowser()
  111.     {
  112.             _uiFlags += BrowseFlags.BIF_BROWSEFORPRINTER;
  113.             Description = "Select a printer:";
  114.             PInvoke.Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.PRINTERS, ref this._rootFolderLocation);
  115.             ShowNewFolderButton = false;
  116.             ShowEditBox = false;
  117.     }       
  118.  
  119.     private void BecomeComputerBrowser()
  120.     {
  121.             _uiFlags += BrowseFlags.BIF_BROWSEFORCOMPUTER;
  122.             Description = "Select a computer:";
  123.             PInvoke.Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.NETWORK, ref this._rootFolderLocation);
  124.             ShowNewFolderButton = false;
  125.             ShowEditBox = false;
  126.     }
  127.  
  128.  
  129.         private class CSIDL
  130.         {
  131.             public const int PRINTERS = 4;
  132.             public const int NETWORK = 0x12;
  133.         }
  134.  
  135.         private class BrowseFlags
  136.         {
  137.             public const int BIF_DEFAULT = 0x0000;
  138.             public const int BIF_BROWSEFORCOMPUTER = 0x1000;
  139.             public const int BIF_BROWSEFORPRINTER = 0x2000;
  140.             public const int BIF_BROWSEINCLUDEFILES = 0x4000;
  141.             public const int BIF_BROWSEINCLUDEURLS = 0x0080;
  142.             public const int BIF_)wNewFoldeqcDL.PRLOWDOMAIN;
  143.      2      public const int BIF_)wNewFoldEDITBOX;
  144.     1       public const int BIF_)wNewFoldNEWDIALOGSTYLE;
  145.     4       public const int BIF_)wNewFoldNONEWFOLDERBUTTON;
  146.    2        public const int BIF_BROWSEINCRETURNFSANCESTOR0;
  147.     08      public const int BIF_BROWSEINCRETURNONLYFSDIR0;
  148.     01      public const int BIF_BROWSEINCSHAREABLE;
  149.   8         public const int BIF_BROWSEINCSTATUSTEX0;
  150.             public const int NETWORK =EINCUAHx20;
  151.    1        public const int BIF_BROWSEINCVALIDATE;
  152.     2       public const int BIF_BROWSEINCNOTRANSLATETARGET0;
  153.    4        publi    private class BrolderBrowseFlags
  154.    orton = Mes 
  155. /  {
  156.             public cos
  157. mes 
  158. /  FROM path otFoldb
  159.     {
  160.       public const int BIF_BROWSEFFM_INITIALIZED;
  161. 1      public const int BIF_BROWSEFFM_SELCHANGED;
  162. 2      public const int BIF_)wNewFFFM_VALIDATEFA400DA;
  163. 3      public const int BIF_)wNewFFFM_VALIDATEFA400DW          public const int NETWORK =EFFM_IUNKNOWN;
  164. 5;   private cccccs
  165. mes 
  166. /  TO path otFoldb
  167.     {
  168.       public const int BIF_BROWSEFFM_SET0TATUSTEX0;
  169.   46       public const int NETWORK =EFFM_ENABLEOK;
  170.   465      public const int NETWORK =EFFM_SET0ELECTIONA;
  171.   466      public const int NETWORK =EFFM_SET0ELECTIONW;
  172.   467      publi    private class BroRK =wserDialogEx(roc _calero, CS 
  173.   ,oRK =msg,rootFolditBram,rootFoldipData  {
  174.             FolderBroswitch (msg)     FolderBro      FolderBrooooocequags
  175.    orton = Mes 
  176. / .EFFM_INITIALIZED:     FolderBrooooooooot ==tFoldeathNeedsChec.Length !
  177.  )     FolderBrooooooooo      FolderBroooooeLlrITIonsN!nt BIF_BROWSEINCVALIDATE;
  178.     2       poooot ==tFoldeF