Skip to content

Commit 7ca2e51

Browse files
Merge pull request #36 from FedeMiorelli/master
Modal ProgressDialog: restore focus to owner
2 parents 0de70c2 + 73430f7 commit 7ca2e51

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Ookii.Dialogs.Wpf/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public enum LoadLibraryExFlags : uint
7474
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
7575
public static extern IntPtr GetActiveWindow();
7676

77+
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
78+
public static extern bool EnableWindow(IntPtr hwnd, bool bEnable);
79+
7780
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
7881
public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
7982

src/Ookii.Dialogs.Wpf/ProgressDialog.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private class ProgressChangedData
5757
private SafeModuleHandle _currentAnimationModuleHandle;
5858
private bool _cancellationPending;
5959
private int _percentProgress;
60+
private IntPtr _ownerHandle;
6061

6162
/// <summary>
6263
/// Event raised when the dialog is displayed.
@@ -758,6 +759,7 @@ private void RunProgressDialog(IntPtr owner, object argument)
758759
if( !MinimizeBox )
759760
flags |= Ookii.Dialogs.Wpf.Interop.ProgressDialogFlags.NoMinimize;
760761

762+
_ownerHandle = owner;
761763
_dialog.StartProgressDialog(owner, null, flags, IntPtr.Zero);
762764
_backgroundWorker.RunWorkerAsync(argument);
763765
}
@@ -778,6 +780,9 @@ private void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerComple
778780
_currentAnimationModuleHandle = null;
779781
}
780782

783+
if (_ownerHandle != IntPtr.Zero)
784+
NativeMethods.EnableWindow(_ownerHandle, true);
785+
781786
OnRunWorkerCompleted(new RunWorkerCompletedEventArgs((!e.Cancelled && e.Error == null) ? e.Result : null, e.Error, e.Cancelled));
782787
}
783788

0 commit comments

Comments
 (0)