Beispiel #1
0
        private bool RunDialogVista(IntPtr hWndOwner)
        {
            FileDialogNative.IFileDialog dialog = CreateVistaDialog();
            OnBeforeVistaDialog(dialog);
            VistaDialogEvents events = new VistaDialogEvents(this);
            uint eventCookie;

            dialog.Advise(events, out eventCookie);
            try
            {
                int result = dialog.Show(hWndOwner);
                return(0 == result);
            }
            finally
            {
                dialog.Unadvise(eventCookie);
                //Make sure that the event interface doesn't get collected
                GC.KeepAlive(events);
            }
        }
Beispiel #2
0
        private bool RunDialogVista(IntPtr hWndOwner)
        {
            uint num;
            bool flag;

            FileDialogNative.IFileDialog dialog = this.CreateVistaDialog();
            this.OnBeforeVistaDialog(dialog);
            VistaDialogEvents pfde = new VistaDialogEvents(this);

            dialog.Advise(pfde, out num);
            try
            {
                int num2 = dialog.Show(hWndOwner);
                flag = 0 == num2;
            }
            finally
            {
                dialog.Unadvise(num);
                GC.KeepAlive(pfde);
            }
            return(flag);
        }
Beispiel #3
0
        internal System.Windows.Forms.DialogResult ShowDialog(System.Windows.Forms.IWin32Window owner, FileDialogNative.IFileDialog f)
        {
            if (!string.IsNullOrEmpty(this.InitialDirectory))
            {
                FileDialogNative.IShellItem item = null;
                try
                {
                    SHCreateItemFromParsingName(this.InitialDirectory, IntPtr.Zero, typeof(FileDialogNative.IShellItem).GUID, out item);
                    f.SetFolder(item);
                }
                catch (Exception e)
                {
                    Util.Logging.Log(e);
                }
                if (item != null)
                {
                    Marshal.ReleaseComObject(item);
                }
            }

            if (!string.IsNullOrEmpty(this.FileName))
            {
                f.SetFileName(this.FileName);
            }

            if (!string.IsNullOrEmpty(this.Filter))
            {
                var filter  = this.Filter.Split('|');
                var filters = new FileDialogNative.COMDLG_FILTERSPEC[filter.Length / 2];

                for (var i = 0; i < filter.Length; i += 2)
                {
                    filters[i / 2] = new FileDialogNative.COMDLG_FILTERSPEC()
                    {
                        pszName = filter[i],
                        pszSpec = filter[i + 1],
                    };
                }

                f.SetFileTypes((uint)filters.Length, filters);
                f.SetFileTypeIndex((uint)this.FilterIndex);
            }

            if (!string.IsNullOrEmpty(this.Title))
            {
                f.SetTitle(this.Title);
            }

            if (f.Show(owner.Handle) == 0)
            {
                FileDialogNative.IShellItem item;
                f.GetResult(out item);

                string ppszName;
                item.GetDisplayName(FileDialogNative.SIGDN.SIGDN_FILESYSPATH, out ppszName);
                Marshal.ReleaseComObject(item);

                this.FileName = ppszName;

                return(System.Windows.Forms.DialogResult.OK);
            }

            return(System.Windows.Forms.DialogResult.Cancel);
        }