Exemple #1
0
        private void RunProgressDialog(IntPtr owner, object argument)
        {
            if (_backgroundWorker.IsBusy)
            {
                throw new InvalidOperationException(Resources.ProgressDialogRunning);
            }

            if (Animation != null)
            {
                try
                {
                    _currentAnimationModuleHandle = Animation.LoadLibrary();
                }
                catch (Win32Exception ex)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
                catch (FileNotFoundException ex)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
            }

            _cancellationPending = false;
            _dialog = new Interop.ProgressDialog();
            _dialog.SetTitle(WindowTitle);
            if (Animation != null)
            {
                _dialog.SetAnimation(_currentAnimationModuleHandle, (ushort)Animation.ResourceId);
            }

            if (CancellationText.Length > 0)
            {
                _dialog.SetCancelMsg(CancellationText, null);
            }
            _dialog.SetLine(1, Text, UseCompactPathsForText, IntPtr.Zero);
            _dialog.SetLine(2, Description, UseCompactPathsForDescription, IntPtr.Zero);

            ProgressDialogFlags flags = ProgressDialogFlags.Normal;

            if (owner != IntPtr.Zero)
            {
                flags |= ProgressDialogFlags.Modal;
            }
            switch (ProgressBarStyle)
            {
            case ProgressBarStyle.None:
                flags |= ProgressDialogFlags.NoProgressBar;
                break;

            case ProgressBarStyle.MarqueeProgressBar:
                if (NativeMethods.IsWindowsVistaOrLater)
                {
                    flags |= ProgressDialogFlags.MarqueeProgress;
                }
                else
                {
                    flags |= ProgressDialogFlags.NoProgressBar; // Older than Vista doesn't support marquee.
                }
                break;
            }
            if (ShowTimeRemaining)
            {
                flags |= ProgressDialogFlags.AutoTime;
            }
            if (!ShowCancelButton)
            {
                flags |= ProgressDialogFlags.NoCancel;
            }
            if (!MinimizeBox)
            {
                flags |= ProgressDialogFlags.NoMinimize;
            }

            _dialog.StartProgressDialog(owner, null, flags, IntPtr.Zero);
            _backgroundWorker.RunWorkerAsync(argument);
        }