.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脚本: #! ...
随机推荐
- C-Lodop提示Access violation at address ...in module 'CLodopPrint32.exe' write of address
C-Lodop提示 Access violation at address ……in module 'CLodopPrint32.exe' write of address ……最近遇到了个问题,上午 ...
- swift 第十课 cocopod 网络请求 Alamofire
这个 cocopod 真的是不容易,差点就放弃了…… 还好,我足够的坚持…… 还是首先说下具体的步骤,希望能记得足够的详细…… 1.打开终端,cd 到自己项目的文件夹 cd 文件路径 2.执行 vim ...
- 如何解决docker 官方镜像拉取慢的问题
转自: http://skycity.today/?thread-307.htm 国内从 docker 官方 Registry 拉取 image 慢的解决,步骤如下: 1.注册一个阿里云账号. 2.阿 ...
- linux /etc/profile bashrc bash_profile
文件: /etc/profile ~/.bashrc 和 ~/.bash_profile 的使用区别: /etc/profile: 全局 环境变量等,在机器重启后执行一次, 用于设置环境变量,更 ...
- 用JavaScript来实现单例模式
首先,了解一下什么是单例模式,这里我直接把菜鸟教程中的定义给copy过来: 单例模式(Singleton Pattern)是 Java 中最简单的设计模式之一.这种类型的设计模式属于创建型模式,它提供 ...
- PJzhang:ms17-010永恒之蓝漏洞在windows 2008R2中的复现
猫宁!!! 参考: https://www.anquanke.com/post/id/86245 https://xz.aliyun.com/t/2536 https://www.cnblogs.co ...
- 牛客竞赛(gcd,快速幂)
一.最大公约数和最小公倍数问题 题目描述: 输入2个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数. 条件:1.P, ...
- layui layer.open弹出框获取不了 input框的值
layer.open({ title:'添加管理员', type: 1, content: $('.add_html').html(), btn:['添加', '取消'], btnAlign:'c', ...
- 【转帖】lmbench的简单使用
https://www.cnblogs.com/mutong1228/p/10485840.html 下载地址 http://www.bitmover.com/lmbench/ tar -zxvf l ...
- 剑指offer32:把数组排成最小的数
1 题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. 2 思路 ...