예제 #1
0
        /// <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;

            if (Helpers.IsWindowsVistaOrGreater())
            {
                Reflector r = new 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(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
            {
                using (FolderBrowserDialog fbd = new FolderBrowserDialog())
                {
                    fbd.Description  = Title;
                    fbd.SelectedPath = InitialDirectory;
                    if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK)
                    {
                        return(false);
                    }
                    ofd.FileName = fbd.SelectedPath;
                    flag         = true;
                }
            }

            return(flag);
        }
예제 #2
0
 public static bool IsDWMEnabled()
 {
     return(Helpers.IsWindowsVistaOrGreater() && DwmIsCompositionEnabled());
 }