本文介绍了从窗口在封闭源代码的第三方Win32应用程序捕获数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划建立一个C#Windows窗体应用程序作为扩展的第三方的Win32应用程序,但我难倒到现在怎么做的权利。我已经得到的是知道它最远涉及的W​​in32挂钩,并且有一个名为EasyHook这个开源项目,是应该允许我这样做。



我想知道我怎么可以从一个文本框,或从第三方Win32应用程序控制其他一些数据的文本。在控制文本/数据是从外部应用程序的运行窗口中用户按下按钮的瞬间捕捉到。



我想这个问题可以概括如下




  1. 你如何确定该事件为
    挂钩,当用户点击某个按钮
  2. $ b? $ b
  3. 你怎么当时由一个Win32控件显示的值
    按钮被点击?


解决方案

例如我创建了一个名为样本为you.then应用程序添加一个文本框。
这是一个C#应用程序,但你也可以使用此方法对所有的Win32应用程序。
首先创建一个名为例子,然后添加一个文本给它一个C#应用程序。你需要文本框的类名
使用这个application.then创建应用程序和
粘贴这些代码。

 使用系统; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;使用System.Windows.Forms的
;使用System.Runtime.InteropServices
;使用System.Diagnostics程序
;

命名空间WindowsFormsApplication1
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent() ;
}
函数[DllImport(user32.dll中)]
公共静态外部INT SendMessage函数(IntPtr的的HWND,INT消息,诠释的wParam,lParam的INT);
函数[DllImport(user32.dll中)]
公共静态外部INT SendMessage函数(IntPtr的的HWND,INT消息,INT的wParam,lParam的StringBuilder的);
函数[DllImport(user32.dll中)]
公共静态外部的IntPtr FindWindowEx(IntPtr的父母,孩子的IntPtr,字符串类名,字符串WINDOWTITLE);
const int的WM_GETTEXT = 0x00D;
const int的WM_GETTEXTLENGTH = 0x00E;
私人无效Form1_Load的(对象发件人,EventArgs五)
{
过程procc = GetProcByName(示例);
//你可以使用间谍++获得主窗口句柄,因此您不需要使用此代码
如果(procc!= NULL)
{
IntPtr的孩子= FindWindowEx( procc.MainWindowHandle,IntPtr.Zero,WindowsForms10.EDIT.app.0.2bf8098_r16_ad1,NULL);
//使用间谍++获取文本框的类名。对我来说,这是WindowsForms10.EDIT.app.0.2bf8098_r16_ad1
INT长度= SendMessage函数(儿童,WM_GETTEXTLENGTH,0,0);
StringBuilder的文本=新的StringBuilder();
文本=新的StringBuilder(长+ 1);
INT retr2 = SendMessage函数(儿童,WM_GETTEXT,长度+ 1,文本);
MessageBox.Show(text.ToString());
//现在你会看到另一个应用程序

}

}
公共流程GetProcByName(字符串名称)$ B $的文本框的值b {
过程PROC = NULL;
过程[] =流程Process.GetProcesses();
的for(int i = 0; I< processes.Length;我++)
{如果(进程[I] .ProcessName ==名称)PROC =过程[I] }
返回PROC;
}

}
}



希望这帮助。


I'm planning on creating a C# Windows Forms app as an extension for a third-party Win32 application but I'm stumped as to how to do this right now. The farthest I've gotten is knowing it involves Win32 Hooking and that there's this open source project called EasyHook that's supposed to allow me to do this.

I'd like to know how I can get the text from a textbox or some other data from a control in a third-party Win32 application. The text/data in a control is to be captured from the external application's running window the moment the user presses a button.

I guess the question can be summed up as follows:

  1. How do you determine the event tohook to when the user clicks a certain button?
  2. How do you get the valuedisplayed by a Win32 control at the time the button is clicked?
解决方案

for example I created a application named 'Example' for you.then added a textbox.it's a c# application but you can use this method for all Win32 applications too.First create a C# application named Example then add a textbox to it.you need to textbox's class name to use this application.then create a application andpaste these codes.

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;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, StringBuilder lParam);
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr Parent,IntPtr child, string classname, string WindowTitle);
        const int WM_GETTEXT = 0x00D;
        const int WM_GETTEXTLENGTH = 0x00E;
        private void Form1_Load(object sender, EventArgs e)
        {
            Process procc = GetProcByName("Example");
            // You can use spy++ to get main window handle so you don't need to use this code
            if (procc != null)
            {
                IntPtr child = FindWindowEx(procc.MainWindowHandle, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2bf8098_r16_ad1", null);
                // Use Spy++ to get textbox's class name. for me it was  "WindowsForms10.EDIT.app.0.2bf8098_r16_ad1"
                int length = SendMessage(child, WM_GETTEXTLENGTH, 0, 0);
                StringBuilder text = new StringBuilder();
                text = new StringBuilder(length + 1);
                int retr2 = SendMessage(child, WM_GETTEXT, length + 1, text);
                MessageBox.Show(text.ToString());
               // now you will see  value of the your textbox on another application  

            }

        }
        public Process GetProcByName(string Name)
        {
            Process proc = null;
            Process[] processes = Process.GetProcesses();
            for (int i = 0; i < processes.Length; i++)
            { if (processes[i].ProcessName == Name)proc = processes[i]; }
            return proc;
        }

    }
}

Hope this help.

这篇关于从窗口在封闭源代码的第三方Win32应用程序捕获数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:38