/// <summary> /// Shows the dialog /// </summary> /// <param name="hWndOwner">Handle of the control to be parent</param> /// <returns>True if the user presses OK else false</returns> public bool ShowDialog(IntPtr hWndOwner) { bool flag = false; if (Environment.OSVersion.Version.Major >= 6) { var r = new FolderSelect.Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { var fbd = new System.Windows.Forms.FolderBrowserDialog(); fbd.Description = this.Title; fbd.SelectedPath = this.InitialDirectory; fbd.ShowNewFolderButton = false; if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != System.Windows.Forms.DialogResult.OK) { return(false); } ofd.FileName = fbd.SelectedPath; flag = true; } return(flag); }
/// <summary> /// Shows the dialog /// </summary> /// <param name="hWndOwner">Handle of the control to be parent</param> /// <returns>True if the user presses OK else false</returns> public bool ShowDialog(IntPtr hWndOwner) { bool flag = false; if (Environment.OSVersion.Version.Major >= 6) { var r = new FolderSelect.Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { var fbd = new System.Windows.Forms.FolderBrowserDialog(); fbd.Description = this.Title; fbd.SelectedPath = this.InitialDirectory; fbd.ShowNewFolderButton = false; if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != System.Windows.Forms.DialogResult.OK) return false; ofd.FileName = fbd.SelectedPath; flag = true; } return flag; }