Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b27c279

Browse files
committed
Use SetForegroundWindow instead of SwitchToThisWindow
SwitchToThisWindow is martked with the following text: [This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]
1 parent f059188 commit b27c279

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/GitHub.VisualStudio.UI/Views/Dialog/LoginCredentialsView.xaml.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public LoginCredentialsView()
4848
this.WhenAnyObservable(
4949
x => x.ViewModel.GitHubLogin.LoginViaOAuth,
5050
x => x.ViewModel.EnterpriseLogin.LoginViaOAuth)
51-
.Subscribe(_ => SwitchToThisWindow());
51+
.Subscribe(_ => SetForegroundWindow());
5252

5353
hostTabControl.SelectionChanged += (s, e) =>
5454
{
@@ -125,19 +125,22 @@ void SetupSelectedTabBindings(Action<IDisposable> d)
125125
.BindTo(this, v => v.enterpriseTab.IsSelected));
126126
}
127127

128-
static void SwitchToThisWindow()
128+
static bool SetForegroundWindow()
129129
{
130130
var hWnd = Process.GetCurrentProcess().MainWindowHandle;
131131
if (hWnd != IntPtr.Zero)
132132
{
133-
NativeMethods.SwitchToThisWindow(hWnd, true);
133+
return NativeMethods.SetForegroundWindow(hWnd);
134134
}
135+
136+
return false;
135137
}
136138

137139
class NativeMethods
138140
{
139141
[DllImport("user32.dll")]
140-
internal static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
142+
[return: MarshalAs(UnmanagedType.Bool)]
143+
internal static extern bool SetForegroundWindow(IntPtr hWnd);
141144
}
142145
}
143146
}

0 commit comments

Comments
 (0)