/// <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); }
/// <summary> /// Resumes the timer on the progress dialog. /// </summary> public void Resume() { if (_state != ProgressDialogState.Paused) { throw new InvalidOperationException("Timer is not paused."); } _nativeProgressDialog.Timer(PDTIMER.Resume, null); _state = ProgressDialogState.Running; }
/// <summary> /// Stops the timer and closes the progress dialog. /// </summary> public void Close() { if (_state != ProgressDialogState.Stopped) { _nativeProgressDialog.StopProgressDialog(); _state = ProgressDialogState.Stopped; } CleanUp(); }
/// <summary> /// Pauses the timer on the progress dialog. /// </summary> public void Pause() { if (_state == ProgressDialogState.Stopped) { throw new InvalidOperationException("Timer is not running."); } if (_state == ProgressDialogState.Running) { _nativeProgressDialog.Timer(PDTIMER.Pause, null); _state = ProgressDialogState.Paused; } }
/// <summary> /// Initialises a new instance of the ProgressDialog class, using default values. /// </summary> public ProgressDialog() { _progressDialogType = Type.GetTypeFromCLSID(new Guid(CLSID_ProgressDialog)); // default/initial values _autoClose = true; _state = ProgressDialogState.Stopped; _maximum = 100; _line1 = _line2 = _line3 = String.Empty; _flags = PROGDLG.Normal | PROGDLG.AutoTime; _title = "Working..."; _cancelMessage = "Aborting..."; }
/// <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); }
/// <summary> /// Initialises a new instance of the ProgressDialog class, using default values. /// </summary> public ProgressDialog() { //_progressDialogType = Type.GetTypeFromCLSID(new Guid(CLSID_ProgressDialog)); // default/initial values _autoClose = true; _state = ProgressDialogState.Stopped; _maximum = 100; _line1 = _line2 = _line3 = String.Empty; _flags = PROGDLG.Normal | PROGDLG.AutoTime; _title = "Working..."; _cancelMessage = "Aborting..."; _statePollingTimer = new System.Threading.Timer(_statePollingTimerCallback, null, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// Releases the RCW to the native IProgressDialog component. /// </summary> private void CleanUp() { if (_nativeProgressDialog != null) { if (_state != ProgressDialogState.Stopped) { try { _nativeProgressDialog.StopProgressDialog(); } catch { } } Marshal.FinalReleaseComObject(_nativeProgressDialog); _nativeProgressDialog = null; } _state = ProgressDialogState.Stopped; }
/// <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)); }
/// <summary> /// Resumes the timer on the progress dialog. /// </summary> public void Resume() { if (_state != ProgressDialogState.Paused) throw new InvalidOperationException("Timer is not paused."); _nativeProgressDialog.Timer(PDTIMER.Resume, null); _state = ProgressDialogState.Running; }
/// <summary> /// Pauses the timer on the progress dialog. /// </summary> public void Pause() { if (_state == ProgressDialogState.Stopped) throw new InvalidOperationException("Timer is not running."); if (_state == ProgressDialogState.Running) { _nativeProgressDialog.Timer(PDTIMER.Pause, null); _state = ProgressDialogState.Paused; } }
/// <summary> /// Stops the timer and closes the progress dialog. /// </summary> public void Close() { if (_state != ProgressDialogState.Stopped) { _nativeProgressDialog.StopProgressDialog(); _state = ProgressDialogState.Stopped; _statePollingTimer.Change(Timeout.Infinite, Timeout.Infinite); } CleanUp(); }
/// <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); }
/// <summary> /// Stops the timer and closes the progress dialog. /// </summary> public void Close() { // Stop the progress dialog if (_state != ProgressDialogState.Stopped) { _nativeProgressDialog.StopProgressDialog(); _state = ProgressDialogState.Stopped; } CleanUp(); }