Windows API 查找窗体,发送Windows消息
最近项目中需要做Windows消息截获操作,在网上找了一些资料。
public class WindowsAPI
{
/// <summary>
/// 回调函数代理
/// </summary>
public delegate bool CallBack(int hwnd, int lParam);
public const int WM_GETTEXT = 0x000D;
public const int WM_SETTEXT = 0x000C;
/// <summary>
/// 鼠标click事件
/// </summary>
public const int WM_CLICK = 0x00F5; public const int WM_KEYUP = 0x0101; #region
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); [DllImport("user32.dll")]
public static extern int GetLastActivePopup(int hWnd);
[DllImport("user32.dll")]
public static extern int AnyPopup();
[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int EnumThreadWindows(int dwThreadId, CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumChildWindows(int hWndParent, CallBack lpfn, int lParam); /// <summary>
/// 获取活动窗体句柄
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, uint wParam, uint lParam); [DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, uint wParam, uint lParam); #endregion /// <summary>
/// 获取枚举描述
/// </summary>
/// <param name="enumValue">枚举值</param>
/// <returns>描述信息</returns>
public static string GetEnumDescription(Enum enumValue)
{
string str = enumValue.ToString();
System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
if (objs == null || objs.Length == ) return str;
System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[];
return da.Description; }
}
至于发送的消息可以通过“Spy++”工具抓取,然后模拟发送。
var pHand = WindowsAPI.FindWindow(null, windowsName);//查找进程窗体
//查找子窗体
var tabControl = WindowsAPI.FindWindowEx(pHand, (IntPtr), "SysTabControl32", ""); //多页选择框,其中第三个参数是第几页,如0,1,2,3,4...
//4912会点击按钮,并切换到对应页。4876只会点按钮,不会切换页 var r = WindowsAPI.SendMessage(tabControl, , , );//// //发送点击事件
int clickPrintDoneOk = WindowsAPI.SendMessage(childHandPrintDoneOk, WindowsAPI.WM_CLICK, , );
Windows API 查找窗体,发送Windows消息的更多相关文章
- c#让窗体永在最前 调用windows api 将窗体设为topmost
有时候应用程序需要将一个窗体始终位于屏幕的最前面,即使切换到其它窗体也能看到该窗体,这样的窗体就叫做TopMost窗体. 用C#制作TopMost窗体之前,首先要了解如何声明SetWindowPos函 ...
- VB用windows API激活子窗体
http://files.cnblogs.com/files/liuzhaoyzz/%E6%BF%80%E6%B4%BB%E5%AD%90%E7%AA%97%E4%BD%93.rar setforeg ...
- 1.java soap api操作和发送soap消息
转自:https://blog.csdn.net/lbinzhang/article/details/84721359 1. /** * soap请求 * * @return * @throws Ex ...
- c# 判断窗体是否永在最前(TopMost),调用windows API
许多程序都可以把自身的窗体设为最前显示状态,这个可以参考博客c#让窗体永在最前 调用windows api 将窗体设为topmost.那么如何判断桌面上的一个窗体是否为最前显示状态呢,不光是自己的程序 ...
- WINDOWS API 大全(二)
9. API之设备场景函数 CombineRgn 将两个区域组合为一个新区域CombineTransform 驱动世界转换.它相当于依顺序进行两次转换CreateCompatibleDC 创建一个与特 ...
- 在VBA中使用Windows API
VBA是一种强大的编程语言,可用于自定义Microsoft Office解决方案.通过使用VBA处理一个或多个Office应用程序对象模型,可以容易地修改Office应用程序的功能或者能够使两个或多个 ...
- WinSpy涉及的windows api
WinSpy涉及的windows api WinSpy是仿造微软Spy++的开源项目,但只涉及Spy++的窗口句柄.窗口的属性.styles.类名子窗口.进程线程信息等查找功能.功能虽然不算强大,但涉 ...
- Windows API的消息处理机制
上个学期找实习失利,让我觉得自己基础打得不够牢固,所以在华为实习的这三个月里,每天下班都在复习理论课的知识,顺便刷了一个月的 LeetCode.本来以为找工作是势在必得了,结果这个学期秋季校招的坑爹经 ...
- C# Windows Api的一些方法 封装 以及 常用参数
using System;using System.Collections.Generic;using System.Drawing;using System.Diagnostics;using Sy ...
随机推荐
- (转)基于OpenStack构建企业私有云(1)实验环境准备
原文:https://www.unixhot.com/article/407 https://www.cnblogs.com/kevingrace/p/5707003.html-----完整部署Cen ...
- 四大组件之Activity——组件间传递数据的4种常用方法
在Android中传递数据的方法非常多,本次介绍4中比较常用的数据传递方法: 通过Intent/Bundle传递数据 通过静态变量(static)传递数据:需构建跳转页面相应静态变量http://bl ...
- DiagnosticFormatter
关于这个类的继承体系如下: 1.DiagnosticFormatter类在com.sun.tools.javac.api包中,其定义如下: /** * Provides simple function ...
- CentOS7服务管理(重启,停止,自动启动命令)
我们对service和chkconfig两个命令都不陌生,systemctl 是管制服务的主要工具, 它整合了chkconfig 与 service功能于一体. systemctl is-enable ...
- python-wsgi测试服务器
#!/usr/bin/python from wsgiref.simple_server import make_server def application(environ,start_respon ...
- js empty() vs remove()
转自:jQuery empty() vs remove() empty() will remove all the contents of the selection. remove() will r ...
- Flex4 初始化过慢解决方法
昨天找了个免费.net空间,想测试一下做的一个简单Flex4 上传项目的效果.上传所有文件到网站之后,访问项目页面,进度条一点一点艰难的向前移动,到了100%后却不出现程序界面,等待一会儿还是没有出现 ...
- throws 与 throw
摘录自:http://blog.csdn.net/ronawilliam/article/details/3299676 void doA() throws Exception1, Exception ...
- Python——爬虫学习2
BeautifulSoup插件的使用 这个插件需要先使用pip安装(在上一篇中不再赘言),然后再程序中申明引用 from bs4 import BeautifulSoup html=self.requ ...
- OpenGL开发入门
1.OpenGL简介: OpenGL ES (OpenGL for Embedded Systems) 是 OpenGL三维图形 API 的子集,针对手机.PDA和游戏主机等嵌入式设备而设计.该API ...