public partial class Form1 : Form
{
public uint VK_RETURN = 0x0D;
public int WM_SETTEXT = 0x000C;
public int WM_KEYDOWN = 0x100;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var iResult = new List<IntPtr>();
IntPtr hwnd = FindWindow(null, "DWS");
//循环窗体下的所有控件
EnumChildWindows(
hwnd,
(h, l) =>
{
IntPtr f1 = FindWindowEx(h, IntPtr.Zero, "WindowsForms10.EDIT.app.0.34f5582_r12_ad1", null);
if (f1 == IntPtr.Zero)
return true;
else
{
iResult.Add(f1);
return true;
}
},
0);
var indexs = int.Parse( textBox1.Text);
SendMessage(iResult.Skip(indexs).Take(1).First(), WM_SETTEXT, IntPtr.Zero, new StringBuilder("00050B80"));
//回车键
SendMessage(iResult.Skip(indexs).Take(1).First(), WM_KEYDOWN, VK_RETURN, 0);
//设置文字
}
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern Int32 SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, StringBuilder lParam);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, uint wParam, uint lParam);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Auto)]
private extern static IntPtr FindWindowEx(IntPtr parent, IntPtr child, string classname, string captionName);
public delegate bool CallBack(IntPtr hwnd, int lParam);
[DllImport("user32.DLL")]
public static extern int EnumChildWindows(IntPtr hWndParent, CallBack lpfn, int lParam);
}
自动化测试(控制其他程序控件)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Xamarin XAML语言教程构建ControlTemplate控件模板 控件模板ControlTemplate...