예제 #1
0
        public void OpDlgTest()
        {
            var idlg = new IOperationsProgressDialog();

            idlg.StartProgressDialog(IntPtr.Zero, OPPROGDLGF.OPPROGDLG_DEFAULT);
            idlg.SetOperation(SPACTION.SPACTION_FORMATTING);
            idlg.SetMode(PDMODE.PDM_RUN);
            idlg.UpdateProgress(0, 0, 0, 0, 0, 100);
            var srcd  = new Vanara.Windows.Shell.ShellFolder(KNOWNFOLDERID.FOLDERID_Documents);
            var destd = new Vanara.Windows.Shell.ShellFolder(KNOWNFOLDERID.FOLDERID_Desktop);

            idlg.UpdateLocations(srcd.IShellItem, destd.IShellItem);
            var rnd = new Random();

            for (uint i = 0; i < 100; i++)
            {
                if (idlg.GetOperationStatus() == PDOPSTATUS.PDOPS_CANCELLED)
                {
                    break;
                }
                idlg.UpdateProgress(i * 1024, 102400, i * 1024, 102400, i, 100);
                Thread.Sleep(rnd.Next(50, 250));
            }
            idlg.StopProgressDialog();
        }
예제 #2
0
        private void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            int hr = _dialog.StopProgressDialog();

            Marshal.ThrowExceptionForHR(hr);
            Marshal.ReleaseComObject(_dialog);
            _dialog = null;
            OnRunWorkerCompleted(new RunWorkerCompletedEventArgs(!e.Cancelled && e.Error == null ? e.Result : null,
                                                                 e.Error, e.Cancelled));
        }
        /// <summary>
        /// Closes the dialog.
        /// </summary>
        public async void Close()
        {
            if (_nativeProgressDialog != null && dialogStatus != DIALOGSTATUS.DLG_DISPOSED)
            {
                _nativeProgressDialog.StopProgressDialog();
                dialogStatus = DIALOGSTATUS.DLG_DISPOSED;
                await Task.Delay(900);

                Marshal.FinalReleaseComObject(_nativeProgressDialog);
                _nativeProgressDialog = null;
            }
        }
        /// <summary>
        /// Shows the dialog with the specified parent. If the parent is null, uses the active form.
        /// </summary>
        /// <param name="parent"></param>
        public void Show(IWin32Window parent)
        {
            if (parent == null)
            {
                parent = Form.ActiveForm;
            }
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            _nativeProgressDialog = (IOperationsProgressDialog)Activator.CreateInstance(_progressDialogType);
            _nativeProgressDialog.StartProgressDialog(handle, dialogFlags);
            _nativeProgressDialog.SetOperation(operationFlags);
            _nativeProgressDialog.SetMode(modeFlags);
            UpdateProgress();
            dialogStatus = DIALOGSTATUS.DLG_RUNNING;
        }
        ///// <summary>
        ///// Not implemented.
        ///// </summary>
        ///// <param name="pszMessage">The window title.</param>
        ///// <exception cref="ObjectDisposedException">Exception thrown when this object is disposed.</exception>
        ///// <exception cref="Win32Exception">Exception thrown when this method fails because of an error in the Win32 COM API implementation.</exception>
        //public void SetProgressMessage(string pszMessage) =>

        //    //if (disposed) throw new ObjectDisposedException(nameof(FileOperation));

        //    //HResult hr = fileOperation.SetProgressMessage(pszMessage);

        //    //if (!CoreErrorHelper.Succeeded(hr))

        //    //    Marshal.ThrowExceptionForHR((int)hr);

        //    throw new NotImplementedException();

        // todo: to encapsulate

        /// <summary>
        /// Specifies a dialog box used to display the progress of the operation.
        /// </summary>
        /// <param name="popd">An <see cref="IOperationsProgressDialog"/> object that represents the dialog box.</param>
        /// <exception cref="ArgumentNullException">Exception thrown when a parameter is null.</exception>
        /// <exception cref="Win32Exception">Exception thrown when this method fails because of an error in the Win32 COM API implementation.</exception>
        public void SetProgressDialog(IOperationsProgressDialog popd)
        {
            ThrowIfNull(popd, nameof(popd));

            if (disposed)
            {
                throw new ObjectDisposedException(nameof(FileOperation));
            }

            HResult hr = fileOperation.SetProgressDialog(popd);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
        }
예제 #6
0
 public OperationsProgressDialog()
     : base()
 {
     instance = (IOperationsProgressDialog)coclassObject;
 }
예제 #7
0
 public OperationsProgressDialog()
     : base()
 {
     instance = (IOperationsProgressDialog)coclassObject;
 }
예제 #8
0
        private void RunProgressDialog(IntPtr owner, object argument)
        {
            if (_backgroundWorker.IsBusy)
            {
                throw new InvalidOperationException(Resources.ProgressDialogRunning);
            }

            _dialog = new Interop.OperationsProgressDialog();

            OperationsProgressDialogFlags flags = OperationsProgressDialogFlags.Normal;

            if (owner != IntPtr.Zero)
            {
                flags |= OperationsProgressDialogFlags.Modal;
            }

            ProgressBarStyle style = ProgressBarStyle;

            if (style == ProgressBarStyle.None)
            {
                flags |= OperationsProgressDialogFlags.NoProgressBar;
            }
            else if (style == ProgressBarStyle.MarqueeProgressBar)
            {
                flags |= OperationsProgressDialogFlags.MarqueeProgress;
            }

            if (ShowTimeRemaining)
            {
                flags |= OperationsProgressDialogFlags.AutoTime;
            }
            if (!ShowCancelButton)
            {
                flags |= OperationsProgressDialogFlags.NoCancel;
            }
            if (!MinimizeBox)
            {
                flags |= OperationsProgressDialogFlags.NoMinimize;
            }
            if (DontDisplaySourcePath)
            {
                flags |= OperationsProgressDialogFlags.DontDisplaySourcePath;
            }
            if (DontDisplayDestPath)
            {
                flags |= OperationsProgressDialogFlags.DontDisplayDestPath;
            }
            if (DontDisplayLocations)
            {
                flags |= OperationsProgressDialogFlags.DontDisplayLocations;
            }
            if (EnablePause)
            {
                flags |= OperationsProgressDialogFlags.EnablePause;
            }
            if (AllowUndo)
            {
                flags |= OperationsProgressDialogFlags.AllowUndo;
            }
            if (NoMultiDayEstimates)
            {
                flags |= OperationsProgressDialogFlags.NoMultiDayEstimates;
            }

            int hr = _dialog.StartProgressDialog(owner, flags);

            Marshal.ThrowExceptionForHR(hr);
            _backgroundWorker.RunWorkerAsync(argument);
        }