public void ShowDialog(params ProgressDialogBehavior[] flags) { if (_progressDialog != null) { return; } _progressDialog = new Win32ProgressDialog() as IProgressDialog; _progressDialog.SetTitle(_title); _progressDialog.SetCancelMsg(_cancelMessage, null); _progressDialog.SetLine(1, _line1, false, IntPtr.Zero); _progressDialog.SetLine(2, _line2, false, IntPtr.Zero); _progressDialog.SetLine(3, _line3, false, IntPtr.Zero); ProgressDialogBehavior dialogFlags = ProgressDialogBehavior.Normal; if (flags.Length != 0) { dialogFlags = flags[0]; for (var i = 1; i < flags.Length; i++) { dialogFlags = dialogFlags | flags[i]; } } _progressDialog.StartProgressDialog(_parentHandle, null, dialogFlags, IntPtr.Zero); }
/// <summary> /// Displays the progress dialog and starts the timer. /// </summary> /// <param name="parent">The dialog box's parent window.</param> public void Show(IWin32Window parent) { // Throw an exception if we are already running if (_state != ProgressDialogState.Stopped) { throw new InvalidOperationException("Timer is already running."); } // Get parent window handle if (parent == null) { parent = Form.ActiveForm; } IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle; // Setup the window _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType); _nativeProgressDialog.SetTitle(_title); _nativeProgressDialog.SetCancelMsg(_cancelMessage, null); if (ShowTimeRemaining) { _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero); } // Create Window _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero); _value = 0; _state = ProgressDialogState.Running; _nativeProgressDialog.Timer(PDTIMER.Reset, null); }
internal static void StartProgressDialog(this IProgressDialog progressDialog, IntPtr hwndParent, string pwzString) { progressDialog.SetTitle(Application.ProductName); progressDialog.SetCancelMsg("Please wait until the current process is finished", IntPtr.Zero); progressDialog.SetLine(1, pwzString, false, IntPtr.Zero); progressDialog.StartProgressDialog(hwndParent, null, (uint)(IPD_Flags.Modal | IPD_Flags.AutoTime | IPD_Flags.NoMinimize), IntPtr.Zero); progressDialog.SetProgress(0, 100); }
/// <summary> /// Displays the progress dialog and starts the timer. /// </summary> /// <param name="parent">The dialog box's parent window.</param> public void Show(IWin32Window parent) { if (_state != ProgressDialogState.Stopped) { throw new InvalidOperationException("Timer is already running."); } if (parent == null) { parent = Form.ActiveForm; } IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle; _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType); _nativeProgressDialog.SetCancelMsg(_cancelMessage, null); if (ShowTimeRemaining) { _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero); } //Temporary title for progressbar handler detection string guidTitle = Guid.NewGuid().ToString(); _nativeProgressDialog.SetTitle(guidTitle); _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero); //Workaround to manipulate progressbar style IntPtr handler = IntPtr.Zero; while (true) { handler = FindWindow(null, guidTitle); if (handler == IntPtr.Zero) { Thread.Sleep(25); } else { break; } } handler = FindWindowEx(handler, IntPtr.Zero, "DirectUIHWND", null); IntPtr childHandler = FindWindowEx(handler, IntPtr.Zero, "CtrlNotifySink", null); childHandler = FindWindowEx(handler, childHandler, "CtrlNotifySink", null); childHandler = FindWindowEx(handler, childHandler, "CtrlNotifySink", null); _progressBarHandler = FindWindowEx(childHandler, IntPtr.Zero, "msctls_progress32", null); //Real title _nativeProgressDialog.SetTitle(_title); _value = 0; _state = ProgressDialogState.Running; _nativeProgressDialog.Timer(PDTIMER.Reset, null); }
public void ShowDialog(IWin32Window Parent, DialogFlags flags) { if (_ProgressDialog == null) { _ProgressDialog = (IProgressDialog) new ProgressDialogClass(); _ProgressDialog.SetTitle(this._Title); _ProgressDialog.SetCancelMsg(this._CancelMessage, null); _ProgressDialog.SetLine(1, this._Line1, false, IntPtr.Zero); _ProgressDialog.SetLine(2, this._Line2, false, IntPtr.Zero); _ProgressDialog.SetLine(3, this._Line3, false, IntPtr.Zero); _ProgressDialog.StartProgressDialog(Parent.Handle, null, flags, IntPtr.Zero); } }
public void InitTest() { var idlg = new IProgressDialog(); idlg.SetTitle("Testing progress"); idlg.SetCancelMsg("Don't like this?"); idlg.SetLine(1, "Doing something really slow.", false); idlg.SetLine(2, @"C:\Users\you\Documents\GitHubRepos\Vanara\UnitTests\PInvoke\Shell32\ProgressDialogTests.cs", true); idlg.StartProgressDialog(IntPtr.Zero, null, PROGDLG.PROGDLG_AUTOTIME); var rnd = new Random(); for (uint i = 0; i < 100; i++) { if (idlg.HasUserCancelled()) { break; } idlg.SetProgress(i, 100); Thread.Sleep(rnd.Next(50, 750)); } idlg.StopProgressDialog(); }
/// <summary> /// Displays the progress dialog and starts the timer. /// </summary> /// <param name="parent">The dialog box's parent window.</param> public void Show(IWin32Window parent) { if (_state != ProgressDialogState.Stopped) throw new InvalidOperationException("Timer is already running."); if (_parentForm == null) _parentForm = Form.ActiveForm; IntPtr handle = parent?.Handle ?? IntPtr.Zero; //_nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType); _nativeProgressDialog = (IProgressDialog) new ProgressDialogImpl(); _nativeProgressDialog.SetTitle(_title); _nativeProgressDialog.SetCancelMsg(_cancelMessage, null); if (ShowTimeRemaining) _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero); _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero); _value = 0; _state = ProgressDialogState.Running; _nativeProgressDialog.Timer(PDTIMER.Reset, null); _statePollingTimer.Change(TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(250)); }
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); }
/// <summary> /// Displays the progress dialog and starts the timer. /// </summary> /// <param name="parent">The dialog box's parent window.</param> public void Show(IWin32Window parent) { // Throw an exception if we are already running if (_state != ProgressDialogState.Stopped) throw new InvalidOperationException("Timer is already running."); // Get parent window handle if (parent == null) parent = Form.ActiveForm; IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle; // Setup the window _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType); _nativeProgressDialog.SetTitle(_title); _nativeProgressDialog.SetCancelMsg(_cancelMessage, null); if (ShowTimeRemaining) _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero); // Create Window _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero); _value = 0; _state = ProgressDialogState.Running; _nativeProgressDialog.Timer(PDTIMER.Reset, null); }