using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace wg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
//查找窗口内控件句柄
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
//发送消息
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);
private void button1_Click(object sender, EventArgs e)
{
IntPtr mW = FindWindow(null, " 身份证联网核查 ");
if (mW != IntPtr.Zero)
{
MessageBox.Show("找到程序窗口!");
IntPtr tabcontrol = FindWindowEx(mW, IntPtr.Zero, "WindowsForms10.SysTabControl32.app.0.33c0d9d", "");
if (tabcontrol == IntPtr.Zero) {
MessageBox.Show("tabcontrol Error!");
}
IntPtr pW = FindWindowEx(tabcontrol, IntPtr.Zero, "WindowsForms10.Window.8.app.0.33c0d9d", "历史记录");
if (pW == IntPtr.Zero) {
MessageBox.Show("pW Error!");
}
IntPtr etw = FindWindowEx(pW, IntPtr.Zero, "WindowsForms10.STATIC.app.0.33c0d9d", "号码:");
if (etw == IntPtr.Zero) {
MessageBox.Show("ETW Error!");
}
IntPtr etw_next = FindWindowEx(pW, etw, null, null);
if (etw_next == IntPtr.Zero)
{
MessageBox.Show("MY_EDIT Error!");
}
IntPtr find = FindWindowEx(pW, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.33c0d9d", "查找");
if (find == IntPtr.Zero)
{
MessageBox.Show("FIND Error!");
}
if (etw_next != IntPtr.Zero)
{
MessageBox.Show("找到文本框!");
StringBuilder s2 = new StringBuilder(512);
SendMessage(etw_next, 0x000d, 510, s2); //0x000d是向控件发送获取文本消息的消息编号
MessageBox.Show(s2.ToString());
s2.Clear();
SendMessage(etw_next, 0x000c, 200, s2);
SendMessage(find, 0x00f5, 200, s2);
}
else
{
MessageBox.Show("没找到文本框!");
}
IntPtr et = FindWindowEx(pW, IntPtr.Zero, "WindowsForms10.EDIT.app.0.33c0d9d", ""); //第三个参数使用spy++找的,不要告诉我不知道呀
if (et != IntPtr.Zero)
{
MessageBox.Show("找到文本框!");
StringBuilder s1 = new StringBuilder(512);
SendMessage(et, 0x000d, 510, s1); //0x000d是向控件发送获取文本消息的消息编号
MessageBox.Show(s1.ToString());
}
else
{
MessageBox.Show("没找到文本框!");
}
IntPtr delete_button = FindWindowEx(pW, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.33c0d9d", "删除");
if (delete_button == IntPtr.Zero)
{
MessageBox.Show("NO Exist delete_button Error!");
}
IntPtr delete_button_next = FindWindowEx(pW, delete_button, null, null);
if (delete_button_next == IntPtr.Zero)
{
MessageBox.Show("NO Exist delete_button_next Error!");
}
if (delete_button_next != IntPtr.Zero)
{
MessageBox.Show("找到文本框!");
StringBuilder s3 = new StringBuilder(512);
SendMessage(delete_button_next, 0x000d, 510, s3); //0x000d是向控件发送获取文本消息的消息编号
s3.Append("1328231981");
s3.Clear();
s3.Append("13282319810602201X");
MessageBox.Show(s3.ToString());
SendMessage(delete_button_next, 0x000c, 510, s3); //0x000d是向控件发送获取文本消息的消息编号
}
else
{
MessageBox.Show("没找到文本框!");
}
IntPtr myprint = FindWindowEx(pW, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.33c0d9d", "打印");
if (myprint != IntPtr.Zero)
{
MessageBox.Show("我是打印按钮开始打印吧");
StringBuilder sss = new StringBuilder(20);
SendMessage(myprint, 0x00f5, 18, sss);
}
}
else
{
MessageBox.Show("没有窗口!");
}
}
}
}