Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Rcp.Utilities/Rcp.Utilities/Rcp.Utilities/WindowHelpers.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (30 sloc)
1.07 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2020 Jeremy Oursler All rights reserved. | |
// Licensed under the MIT License. See License.txt in the project root for license information. | |
using System; | |
using System.Diagnostics; | |
using System.Runtime.InteropServices; | |
namespace Rcp.Utilities | |
{ | |
public class WindowHelpers | |
{ | |
private static class User32 | |
{ | |
[DllImport("User32.dll")] | |
internal static extern IntPtr SetForegroundWindow(IntPtr hWnd); | |
[DllImport("user32.dll")] | |
internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); | |
internal static readonly IntPtr InvalidHandleValue = IntPtr.Zero; | |
internal const int SW_SHOWNORMAL=1; | |
} | |
public static void Activate() | |
{ | |
Process currentProcess = Process.GetCurrentProcess(); | |
IntPtr hWnd = currentProcess.MainWindowHandle; | |
if (hWnd != User32.InvalidHandleValue) | |
{ | |
User32.SetForegroundWindow(hWnd); | |
User32.ShowWindow(hWnd, User32.SW_SHOWNORMAL); | |
} | |
} | |
} | |
} |