Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从封闭源代码第三方Win32应用程序中的窗口捕获数据_C#_Winforms_Winapi_Interop_Hook - Fatal编程技术网

C# 从封闭源代码第三方Win32应用程序中的窗口捕获数据

C# 从封闭源代码第三方Win32应用程序中的窗口捕获数据,c#,winforms,winapi,interop,hook,C#,Winforms,Winapi,Interop,Hook,我正计划创建一个C#Windows窗体应用程序,作为第三方Win32应用程序的扩展,但我现在还不知道该怎么做。我所知道的最远的情况是它涉及到Win32挂钩,还有一个叫做EasyHook的开源项目,它应该允许我这样做 我想知道如何从第三方Win32应用程序中的文本框或控件获取文本或其他数据。控件中的文本/数据将在用户按下按钮时从外部应用程序的运行窗口捕获 我想问题可以总结如下: 您如何确定要进行的活动 当用户单击某个按钮时挂钩到 你如何获得价值 单击按钮时由Win32控件显示 例如,我为您创建了一

我正计划创建一个C#Windows窗体应用程序,作为第三方Win32应用程序的扩展,但我现在还不知道该怎么做。我所知道的最远的情况是它涉及到Win32挂钩,还有一个叫做EasyHook的开源项目,它应该允许我这样做

我想知道如何从第三方Win32应用程序中的文本框或控件获取文本或其他数据。控件中的文本/数据将在用户按下按钮时从外部应用程序的运行窗口捕获

我想问题可以总结如下:

  • 您如何确定要进行的活动 当用户单击某个按钮时挂钩到
  • 你如何获得价值 单击按钮时由Win32控件显示

  • 例如,我为您创建了一个名为“example”的应用程序,然后添加了一个文本框。 这是一个c#应用程序,但您也可以将此方法用于所有Win32应用程序。 首先创建一个名为Example的C#应用程序,然后在其中添加一个文本框。 您需要输入textbox的类名才能使用此应用程序。然后创建一个应用程序并 粘贴这些代码

    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;
            }
    
        }
    }
    
    使用系统;
    使用System.Collections.Generic;
    使用系统组件模型;
    使用系统数据;
    使用系统图;
    使用System.Linq;
    使用系统文本;
    使用System.Windows.Forms;
    使用System.Runtime.InteropServices;
    使用系统诊断;
    命名空间Windows窗体应用程序1
    {
    公共部分类Form1:Form
    {
    公共表格1()
    {
    初始化组件();
    }
    [DllImport(“user32.dll”)]
    公共静态外部int SendMessage(IntPtr hWnd、int Msg、int wParam、int lParam);
    [DllImport(“user32.dll”)]
    公共静态外部int SendMessage(IntPtr hWnd、int Msg、int wParam、StringBuilder lParam);
    [DllImport(“user32.dll”)]
    公共静态外部IntPtr FindWindowEx(IntPtr父级、IntPtr子级、字符串类名称、字符串窗口标题);
    常量int WM_GETTEXT=0x00D;
    常量int WM_GETTEXTLENGTH=0x00E;
    私有void Form1\u加载(对象发送方、事件参数e)
    {
    进程procc=GetProcByName(“示例”);
    //您可以使用spy++获取主窗口句柄,因此不需要使用此代码
    如果(procc!=null)
    {
    IntPtr child=FindWindowEx(procc.MainWindowHandle,IntPtr.Zero,“WindowsForms10.EDIT.app.0.2bf8098_r16_ad1”,null);
    //使用Spy++获取textbox的类名。对我来说,它是“WindowsForms10.EDIT.app.0.2bf8098_r16_ad1”
    int length=SendMessage(child,WM_GETTEXTLENGTH,0,0);
    StringBuilder text=新的StringBuilder();
    text=新的StringBuilder(长度+1);
    int retr2=SendMessage(child,WM_GETTEXT,长度+1,text);
    Show(text.ToString());
    //现在,您将在另一个应用程序上看到文本框的值
    }
    }
    公共进程GetProcByName(字符串名称)
    {
    processproc=null;
    Process[]processs=Process.getprocesss();
    for(int i=0;i
    希望这有帮助。

    不,不,不!使用。它是官方的、受支持的和有文档记录的界面,可以使第三方应用程序自动化。为按钮设置事件侦听器,并在触发时检索文本框内容。