为啥我的postmessage 到记事本的按键信息无效, 哪位大大帮我分析一下?
已经注意子窗口的问题了, 对比spy++的句柄,没有找错edit控件窗口, 但无法写进去 。 看了msdn,也将焦点重置加入,还是无法写入,不知是什么原因?using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace SendKeyInfo
{
class SendController
{
// 导入窗口名称列表
const string titleW = "notepad";
private const int WM_KEYDOWN = 0x0100;
private const int WM_KEYUP = 0x0101;
private const int WM_SETFOCUS = 0x0007;
private const int WM_LOSTFOCUS = 0x0008;
private const int WM_CHAR = 0x0102;
private const int VK_S = 83;
int p_hWnd, hProcess, delay, PID,child;
public bool sclick()
{
p_hWnd = SendUtil.FindWindowExA(0, 0, titleW, null);
if (p_hWnd == 0)
{
MessageBox.Show("请先启动!");
return false;
}
else
{
child = SendUtil.FindWindowExA(p_hWnd,0,"edit" ,null);
MessageBox.Show(child+"");
SendUtil.GetWindowThreadProcessId(child, out PID);
SendUtil.PostMessageA(PID, WM_LOSTFOCUS, 0, 0);
SendUtil.PostMessageA(PID, WM_SETFOCUS, 0, 0);
SendUtil.SendMessageA(PID, WM_KEYDOWN, VK_S, 0);
SendUtil.PostMessageA(PID, WM_CHAR, '1', 0);
MessageBox.Show("....");
return true;
}
}
}
}
--------------------编程问答-------------------- 自己顶一下.............. --------------------编程问答-------------------- 继续顶..... --------------------编程问答-------------------- 顶到有人回......
补充:.NET技术 , C#