-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetForegroundWindowCmd.cs
More file actions
68 lines (61 loc) · 2.06 KB
/
SetForegroundWindowCmd.cs
File metadata and controls
68 lines (61 loc) · 2.06 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//-------------------------------------------------------------------
// Copyright © 2012 Kindel Systems, LLC
// http://www.kindel.com
// charlie@kindel.com
//
// Published under the MIT License.
// Source control on SourceForge
// http://sourceforge.net/projects/mcecontroller/
//-------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using Microsoft.Win32.Security;
namespace MCEControl
{
using HWND = IntPtr;
using DWORD = UInt32;
/// <summary>
/// Summary description for SetForegroundWindowCommand.
/// </summary>
public class SetForegroundWindowCommand : Command
{
[XmlAttribute("ClassName")]
public string ClassName;
[XmlAttribute("WindowName")]
public string WindowName;
public SetForegroundWindowCommand()
{
}
public SetForegroundWindowCommand(string className, string windowName)
{
ClassName = className;
WindowName = windowName;
}
public override void Execute(Reply reply)
{
try
{
if (ClassName != null)
{
var procs = Process.GetProcessesByName(ClassName);
if (procs.Length > 0)
{
var h = procs[0].MainWindowHandle;
MainWindow.AddLogEntry("Cmd: SetForegroundWindow(\"" + ClassName + "\")");
Win32.SetForegroundWindow(h);
}
else
{
MainWindow.AddLogEntry("Cmd: GetProcessByName for " + ClassName + " failed");
}
}
}
catch (Exception e)
{
MainWindow.AddLogEntry("Cmd: SetForegroundWindowCommand.Execute failed for " + ClassName + " with error: " +
e.Message);
}
}
}
}