C#示例代码,分享给大家使用,功能还是慢慢体会吧!

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("没有窗口!");
            }
        }

    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_39410618

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值