@@ -30,16 +30,16 @@ public interface IGui
30
30
31
31
public class Gui : IGui
32
32
{
33
- private readonly IntPtr ? _parentHwnd ;
33
+ private readonly IntPtr _parentHwnd = IntPtr . Zero ;
34
34
35
35
public Gui ( )
36
36
{
37
- _parentHwnd = null ;
38
- }
37
+ string envar = Environment . GetEnvironmentVariable ( Constants . EnvironmentVariables . GcmParentWindow ) ;
39
38
40
- public Gui ( IntPtr parentHwnd )
41
- {
42
- _parentHwnd = parentHwnd ;
39
+ if ( long . TryParse ( envar , out long ptrInt ) )
40
+ {
41
+ _parentHwnd = new IntPtr ( ptrInt ) ;
42
+ }
43
43
}
44
44
45
45
public bool ShowDialogWindow ( Func < Window > windowCreator )
@@ -50,7 +50,7 @@ public bool ShowDialogWindow(Func<Window> windowCreator)
50
50
{
51
51
var window = windowCreator ( ) ;
52
52
53
- windowResult = window . ShowDialog ( _parentHwnd ) ?? false ;
53
+ windowResult = ShowDialog ( window , _parentHwnd ) ?? false ;
54
54
} )
55
55
. Wait ( ) ;
56
56
@@ -67,7 +67,7 @@ public bool ShowViewModel(ViewModel viewModel, Func<Window> windowCreator)
67
67
68
68
window . DataContext = viewModel ;
69
69
70
- windowResult = window . ShowDialog ( _parentHwnd ) ?? false ;
70
+ windowResult = ShowDialog ( window , _parentHwnd ) ?? false ;
71
71
} )
72
72
. Wait ( ) ;
73
73
@@ -95,25 +95,17 @@ private static Task StartSTATask(Action action)
95
95
96
96
return completionSource . Task ;
97
97
}
98
- }
99
-
100
- public static class WindowExtensions
101
- {
102
- public static void SetOwnerHandle ( this Window window , IntPtr hwnd )
103
- {
104
- new System . Windows . Interop . WindowInteropHelper ( window ) . Owner = hwnd ;
105
- }
106
98
107
- public static bool ? ShowDialog ( this Window window , IntPtr ? parentHwnd )
99
+ public static bool ? ShowDialog ( Window window , IntPtr parentHwnd )
108
100
{
109
101
// Zero is not a valid window handles
110
- if ( ! parentHwnd . HasValue || parentHwnd . Value == IntPtr . Zero )
102
+ if ( parentHwnd == IntPtr . Zero )
111
103
{
112
104
return window . ShowDialog ( ) ;
113
105
}
114
106
115
107
// Set the parent window handle and ensure the dialog starts in the correct location
116
- window . SetOwnerHandle ( parentHwnd . Value ) ;
108
+ new System . Windows . Interop . WindowInteropHelper ( window ) . Owner = parentHwnd ;
117
109
window . WindowStartupLocation = WindowStartupLocation . CenterOwner ;
118
110
119
111
const int ERROR_INVALID_WINDOW_HANDLE = 1400 ;
0 commit comments