Skip to content

Commit 73430f7

Browse files
FedeMiorelliaugustoproiete
authored andcommitted
Modal ProgressDialog: restore focus to owner
When using a modal ProgressDialog (with ShowDialog()) the focus does not return to the owner window. Additionally, when running under Wine emulation on Linux, the window becomes unresponsive as it remains in disabled state. This patch restores the behavior by calling user32.dll EnableWindow on the owner handle
1 parent 0de70c2 commit 73430f7

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)