Example #1
0
        public DialogResult ShowDialog(IWin32Window owner, IFileDialogUICallbacks uiCallbacks)
        {
            if (uiCallbacks == null)
            {
                throw new ArgumentNullException("uiCallbacks");
            }

            this.uiCallbacks = uiCallbacks;

            int hrCCD = FileDialog.ClearClientData();

            uint dwCookie = 0xdeadbeef;

            if (this.fileDialogEvents != null)
            {
                FileDialog.Advise(this.fileDialogEvents, out dwCookie);
            }

            OnBeforeShow();

            int hr = 0;

            UI.InvokeThroughModalTrampoline(
                owner,
                delegate(IWin32Window modalOwner)
            {
                hr = this.fileDialog.Show(modalOwner.Handle);
                GC.KeepAlive(modalOwner);
            });

            DialogResult result;

            if (hr >= 0)
            {
                result = DialogResult.OK;
            }
            else
            {
                result = DialogResult.Cancel;
            }

            this.dialogResult = result;

            if (this.fileDialogEvents != null)
            {
                FileDialog.Unadvise(dwCookie);
            }

            OnAfterShow();
            this.uiCallbacks = null;

            GC.KeepAlive(owner);
            return(result);
        }