C# 获得其他(另外)应用程序(窗口)文本框内容的弱智方法,网上的那些狗屎文章,居然排名第一,搜素引擎真特么是个狗屁,为此,我整整找了好几天。

// Program.cs
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.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        //查找窗口API
        [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, "MyForm");
            if (mW != IntPtr.Zero)
            {
                MessageBox.Show("找到程序窗口!");
                IntPtr et = FindWindowEx(mW, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2bf8098_r16_ad1", null); //第三个参数使用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("没找到文本框!");
                }
            }
            else {
                MessageBox.Show("没有窗口!");
            }
        }

       

       
    }
}

 

  • 7
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

weixin_39410618

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

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

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

打赏作者

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

抵扣说明:

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

余额充值