LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

C# 获得其他应用程序窗口中按钮、列表、文本框等控件内容的方法

admin
2023年12月29日 23:30 本文热度 563

 

 代码如下:

1.  // Program.cs

2.  using System;

3.  using System.Collections.Generic;

4.  using System.ComponentModel;

5.  using System.Data;

6.  using System.Drawing;

7.  using System.Linq;

8.  using System.Text;

9.  using System.Windows.Forms;

10.using System.Diagnostics;

11.using System.Runtime.InteropServices;

12.

13.namespace WindowsFormsApplication4

14.{

15.    public partial class Form1 : Form

16.    {

17.        public Form1()

18.        {

19.            InitializeComponent();

20.        }

21.

22.        //查找窗口API

23.        [DllImport("user32.dll", EntryPoint = "FindWindow")]

24.        public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

25.

26.        //查找窗口内控件句柄

27.        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]

28.        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

29.

30.        //发送消息

31.

32.        [DllImport("user32.dll", EntryPoint = "SendMessageA")]

33.        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);

34.

35.        private void button1_Click(object sender, EventArgs e)

36.        {

37.            IntPtr mW = FindWindow(null, "MyForm");

38.            if (mW != IntPtr.Zero)

39.            {

40.                MessageBox.Show("找到程序窗口!");

41.                IntPtr et = FindWindowEx(mW, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2bf8098_r16_ad1", null); //第三个参数使用spy++找的,不要告诉我不知道呀

42.                if (et != IntPtr.Zero) {

43.                    MessageBox.Show("找到文本框!");

44.

45.

46.                    StringBuilder s1 = new StringBuilder(512);

47.                    SendMessage(et, 0x000d, 510, s1); //0x000d是向控件发送获取文本消息的消息编号

48.                    MessageBox.Show(s1.ToString());

49.                } else {

50.                    MessageBox.Show("没找到文本框!");

51.                }

52.            }

53.            else {

54.                MessageBox.Show("没有窗口!");

55.            }

56.        }

57.    }

58.}


该文章在 2023/12/29 23:30:37 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved