日期:2014-05-17 浏览次数:21094 次
public const int WM_USER = 0x500;
public const int RF_CMD = WM_USER + 13;
public struct RFDataStruct
{
public int rfLength;
public string rfData;
}
byte rfCmd = 0;
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, ref RFDataStruct lparam);
private void buttonSend_Click(object sender, EventArgs e)
{
Process[] vProcesses = Process.GetProcessesByName("PorcessReceiveUserDefinedMessageDemo"); // 查询目标进程
if (vProcesses.Length <= 0)
vProcesses = Process.GetProcessesByName("PorcessReceiveUserDefinedMessageDemo.vshost"); //Debug调试进程
if (vProcesses.Length <= 0)
{
MessageBox.Show("目标进程没有找到!");
return;
}
if (comboBoxRF.Text == comboBoxRF.Items[0].ToString()) rfCmd = 0;
else if (comboBoxRF.Text == comboBoxRF.Items[1].ToString()) rfCmd = 1;
else if (comboBoxRF.Text == comboBoxRF.Items[2].ToString()) rfCmd = 2; //SelectedText不行,始终为空
else rfCmd = 3;
string rfCmdString = rfCmd.ToString("X2");
RFDataStruct rfMessage = new RFDataStruct();
rfMessage.rfData = rfCmdString;
rfMessage.rfLength = rfMessage.rfData.Length;
foreach (Process vProcess in vProcesses)
&nbs