.net 调用 winapi获取窗口句柄和内容
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace cstest
{
public partial class Form1 : Form
{
//定义一个符合WINAPI返回值和参数的委托
public delegate bool CallBack(IntPtr hwnd, int lParam);
//声明符合上述委托的函数(定义一个函数指针)
private static CallBack myCallBack;
public Form1()
{
myCallBack = new CallBack(Report);
InitializeComponent();
GetHandle("C#");
this.textBox1.Multiline = true;
this.textBox1.Dock = DockStyle.Fill;
} private void GetHandle(string windcaption)
{
IntPtr mainHandle = FindWindow(null, windcaption);
if (IntPtr.Zero != mainHandle)
{
AppendText(string.Format("{0}句柄:{1}", windcaption, Convert.ToString((int)mainHandle,))); //EnumChildWindows((int)mainHandle, myCallBack, 0);
//修改窗口标题
SetWindowText((int)mainHandle, "C#");
StringBuilder s = new StringBuilder();
//获取控件标题
int i = GetWindowText(mainHandle, s, s.Capacity);
AppendText(string.Format("句柄{0}的caption:{1}", Convert.ToString((int)mainHandle, ), s.ToString()));
//枚举所有子窗体,并将子窗体句柄传给myCallBack
EnumChildWindows((int)mainHandle, myCallBack, );
}
} private void AppendText(string msg)
{
this.textBox1.AppendText(msg);
this.textBox1.AppendText("\r\n");
}
//根据窗体句柄,输出窗体caption
public bool Report(IntPtr hWnd, int lParam)
{
StringBuilder s = new StringBuilder();
int i = GetWindowText((IntPtr)hWnd, s, s.Capacity);
AppendText(string.Format("句柄{0}的caption:{1}", Convert.ToString((int)hWnd, ), s.ToString()));
return true;
} /// <summary>
/// 获取窗体的句柄函数
/// </summary>
/// <param name="lpClassName">窗口类名</param>
/// <param name="lpWindowName">窗口标题名</param>
/// <returns>返回句柄</returns>
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")]
public static extern int EnumWindows(CallBack x, int y); [DllImport("user32.dll")]
private static extern IntPtr EnumChildWindows(int hWndParent, CallBack lpEnumFunc, int lParam); [DllImport("user32.dll")]
public static extern int SetWindowText(int handle, string title); [DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString,int cch); [DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, StringBuilder lParam); private void button1_Click(object sender, EventArgs e)
{
StringBuilder s = new StringBuilder();
//获取控件标题,对TRichEdit无效
//int i = GetWindowText((IntPtr)int.Parse(txtHandle.Text), s, s.Capacity);
//获取控件标题,对TRichEdit有效
int i = SendMessage((IntPtr)int.Parse(txtHandle.Text), 0x000D, , s);
AppendText(string.Format("句柄{0}的caption:{1}", txtHandle.Text, s.ToString()));
}
}
}
.net 调用 winapi获取窗口句柄和内容的更多相关文章
- [WinAPI] 获取窗口句柄的几种方法
1.使用FindWindow函数获取窗口句柄 示例:使用FindWindow函数获取窗口句柄,然后获得窗口大小,并且移动窗口到指定位置. 我们想获得酷我音乐盒的窗口句柄并移动它,该怎么办呢? 首先打开 ...
- C#调用WinAPI及窗口过程
C#调用WINAPI及Windows窗口消息的发与送 最近在做一个餐饮项目(C#Winform),其中有一块是做点菜宝接口的对接,点菜宝的厂商提供了一个WX.exe的驱动程序,这个驱动程序无直接打开, ...
- java分别通过httpclient和HttpURLConnection获取图片验证码内容
前面的文章,介绍了如何通过selenium+Tesseract-OCR来识别图片验证码,如果用接口来访问的话,再用selenium就闲的笨重,下面就介绍一下分别通过httpclient和HttpURL ...
- windows获取窗口句柄
1.使用FindWindow函数获取窗口句柄 示例:使用FindWindow函数获取窗口句柄,然后获得窗口大小和标题,并且移动窗口到指定位置. #include <Windows.h> # ...
- phpcms-v9 --- 如何通过{pc}标签获取全站文章内容?
1.phpcms-v9默认情况下只能根据catid获取当前栏目及子栏目下的文章,但是有时候我们需要如何通过{pc}标签来获取全站文章内容的需求,应该怎么做呢? 第一步:在content_tag.cla ...
- SpringMVC——使用RequestDispatcher.include()和HttpServletResponseWrapper动态获取jsp输出内容
介绍本篇内容前,先抛出我遇到的问题或者说是需求!(精读阅读本篇可能花费您15分钟,略读需5分钟左右) 一:需求说明 有一个Controller有两个方法 第一个方法通过指定的路径和参数去渲染jsp内容 ...
- 从IE浏览器获取当前页面的内容
从IE浏览器获取当前页面内容可能有多种方式,今天我所介绍的是其中一种方法.基本原理:当鼠标点击当前IE页面时,获取鼠标的坐标位置,根据鼠标位置获取当前页面的句柄,然后根据句柄,调用win32的东西进而 ...
- Python获取网页指定内容(BeautifulSoup工具的使用方法)
Python用做数据处理还是相当不错的,如果你想要做爬虫,Python是很好的选择,它有很多已经写好的类包,只要调用,即可完成很多复杂的功能,此文中所有的功能都是基于BeautifulSoup这个包. ...
- python3获取指定目录内容的详细信息
不同平台获取指定目录内容的详细信息命令各不相同: Linux中可以通过ls -al获取获取 windows中可以通过dir命令获取 下面是我写的一个通用获取目录内容详细信息的python3脚本: #! ...
随机推荐
- 模型压缩-L1-norm based channel pruning(Pruning Filters for Efficient ConvNets)
论文笔记——PRUNING FILTERS FOR EFFICIENT CONVNETS 转载:https://www.cnblogs.com/zhonghuasong/p/7642000.html ...
- Kibana——安装部署
1.准备 JDK:1.8版本及以上: Kibana:6.2.4版本: 2.安装 2.1.下载解压 wget https://artifacts.elastic.co/downloads/kibana/ ...
- iOS Xib布局某些控件显示或隐藏<约束的修改>
对于这个问题使用Masonry是很好解决的. 注意:绿色的是label2,当indexpath.section % 2 == 0时,label2不存在. 关键代码如下: if (indexPath.s ...
- PHP常用正则表达式精选
$regex = '[\u4e00-\u9fa5]'; //匹配中文字符的正则表达式 $regex = '^[\u4E00-\u9FA5A-Za-z0-9]+$'; or $regex = '^[\u ...
- JavaScript中new运算符的实现
废话不多说直接进入正题,首先我们需要先知道new运算符到底做了哪些事情,再来模拟它实现这一功能. 1. 建立一个空的Object对象: 2. 把这个空对象用__proto__链接到原型 3. 用app ...
- Oracle导出包含clob字段的sql脚本工具
之前工作中遇到生产环境不允许导入Oracle的dmp文件,只能导入sql脚本,但是表中存在clob字段,直接用plsql工具无法导出clob字段,用了下dbvisualizer可以直接导出,亲测可用. ...
- ZoomEye
* https://www.zoomeye.org/ *类似工具 IVRE 1. 摄像头漏洞 (1)http://www.2cto.com/Article/201401/269458.html (2) ...
- Flask Bug记录之JinJa2.exceptions.UndefinedError: 'sqlite3.Row object' has no attribute 'get'
源码 py文件定义db的工厂函数如下 def get_db(): if "db" not in g: g.db = sqlite3.connect( current_app.con ...
- linux下如何查看一个服务所在的安装路径?
当接手一个不是自己维护的linux服务器,我们常常会想要看看该服务器上是否安装了某个服务,这个服务安装的路径在哪? redis 是开发过程中常常会用到的一个服务,我这里就以这个服务为例,进行说明. 1 ...
- Spring Boot环境的安装
Eclipse 使用springboot框架 环境的安装 1.下载java1.8 ,安装并配置环境变量 环境变量增加java 的安装目录到环境变量中path中增加 %JAVA_HOME%/bin增加变 ...