-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWindowHelper.cs
30 lines (24 loc) · 1.01 KB
/
WindowHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Runtime.InteropServices;
namespace KeepRDPAlive
{
class WindowHelper
{
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/* [DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
*/
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("USER32.DLL")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsIconic(IntPtr hWnd);
public static IntPtr FindTerminalServicesWindowByHost(string remoteHost)
{
return WindowHelper.FindWindow("TscShellContainerClass", string.Format("{0} - Remote Desktop Connection", remoteHost));
}
}
}