-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendMessageCommands.cs
More file actions
88 lines (78 loc) · 2.88 KB
/
SendMessageCommands.cs
File metadata and controls
88 lines (78 loc) · 2.88 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//-------------------------------------------------------------------
// 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 SendMessageCommand.
/// </summary>
public class SendMessageCommand : Command
{
[XmlAttribute("Msg")]
public int Msg;
// This is int so that -1 can be specified in the XML
[XmlAttribute("lParam")]
public int LParam;
[XmlAttribute("wParam")]
public int WParam;
public SendMessageCommand()
{
}
public SendMessageCommand(string className, string windowName, DWORD msg, DWORD wParam, DWORD lParam)
{
ClassName = className;
WindowName = windowName;
Msg = (int)msg;
WParam = (int)wParam;
LParam = (int)lParam;
}
[XmlAttribute("ClassName")]
public string ClassName { get; set; }
[XmlAttribute("WindowName")]
public string WindowName { get; set; }
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(string.Format("Cmd: SendMessage ({0}): {1} {2} {3}", ClassName, Msg, WParam,
LParam));
Win32.SendMessage(h, (DWORD)Msg, (DWORD)WParam, (DWORD)LParam);
}
else
{
MainWindow.AddLogEntry("Cmd: GetProcessByName for " + ClassName + " failed");
}
}
else
{
var h = Win32.GetForegroundWindow();
MainWindow.AddLogEntry(string.Format("Cmd: SendMessage (forground window): {0} {1} {2}", Msg, WParam, LParam));
Win32.SendMessage(h, (DWORD)Msg, (DWORD)WParam, (DWORD)LParam);
}
}
catch (Exception e)
{
MainWindow.AddLogEntry("Cmd: SendMessageCommand.Execute failed for " + ClassName + " with error: " +
e.Message);
}
}
}
}