资源简介
通过窗口名获取程序所有控件句柄,并绘制句柄结构树。
代码片段和文件信息
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 spyTree
{
public partial class Form1 : Form
{
[DllImport(“User32.dll“ EntryPoint = “FindWindow“)]
private static extern int FindWindow(string lpClassName string lpWindowName);
[DllImport(“user32.dll“)]//在窗口列表中寻找与指定条件相符的第一个子窗口
private static extern int FindWindowEx(
int hwndParent // handle to parent window
int hwndChildAfter // handle to child window
string className //窗口类名
string windowName // 窗口标题
);
[DllImport(“User32.dll“ CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd StringBuilder ClassName int nMaxCount);
[DllImport(“user32.dll“)]
public static extern int GetWindowText(int hwnd StringBuilder lpString int nMaxCount);//获取窗体标题名称
[DllImport(“user32.dll“ EntryPoint = “SendMessageA“)]
public static extern int SendMessage(int hwnd int wMsg int wParam string lParam);
public Form1()
{
InitializeComponent();
}
int WM_GETTEXT = 0x0D;
private void getChildHwd(int parent_hwdTreeNode treeNode) {
int past_hwd = 0;
int i = 1;
List list = new List();
while(past_hwd!=0||i==1)
{
i++;
past_hwd = FindWindowEx(parent_hwd past_hwd null null);
if (past_hwd > 0)
{
StringBuilder sb = new StringBuilder();
int maxcount=0;
IntPtr intsb = new IntPtr(past_hwd);
GetClassName(intsbsb 255);
getChildHwd(past_hwd treeNode.Nodes.Add(past_hwd + “|“ + sb.ToString()));
}
}
//return list;
}
private void Button1_Click(object sender EventArgs e)
{
try
{
int intPtr = FindWindow(null window_title_text.Text.Trim());
if (intPtr == 0)
{
MessageBox.Show(“此标题窗口不存在!!!“ “错误“);
}
else
{
treeView1.Nodes.Clear();
getChildHwd(intPtr treeView1.Nodes.Add(intPtr + “|“ + window_title_text.Text.Trim()));
//;
}
}
catch (Exception ex) {
throw ex;
}
}
private int select_node_hwnd = 0;
private void TreeView1_NodeMouseDouble
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论