C#调用API函数EnumWindows枚举窗口的方法
原文 http://blog.csdn.net/dengta_snowwhite/article/details/6067928
与C++不同,C#调用API函数需要引入.dll文件,步骤如下:
1. 添加命名空间
using System.Runtime.InteropServices;
2. DllImport调入EnumWindows等函数
[DllImport("user32.dll")]
//EnumWindows函数,EnumWindowsProc 为处理函数
private static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
其他常用函数格式如下:
[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(int hWnd);
[DllImport("user32.dll")]
private static extern int GetWindowTextLength(int hWnd);
[DllImport("USER32.DLL")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("USER32.DLL")]
private static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
3. 申明委托
public delegate bool EnumWindowsProc(int hWnd, int lParam);
4.定义委托函数,ADA_EnumWindowsProc为执行函数,返回true则EnumWindows继续枚举下一个顶级窗口直到枚举完
EnumWindowsProc ewp = new EnumWindowsProc(ADA_EnumWindowsProc);
EnumWindows(ewp, 0);
5. 实现委托函数
public bool ADA_EnumWindowsProc(int hWnd, int lParam)
{
int cTxtLen, i;
String cTitle, strtmp;
if (IsWindowVisible(hWnd))
{
//..........对每一个枚举窗口的处理
//Get the task name
cTxtLen = GetWindowTextLength(hWnd) +1;
StringBuilder text = new StringBuilder(cTxtLen);
GetWindowText(hWnd, text, cTxtLen);
cTitle = text.ToString();
cTitle = cTitle.ToUpper();
//...............
}
return true;
}
C#调用API函数EnumWindows枚举窗口的方法的更多相关文章
- 在C#中调用Win32函数EnumWindows枚举所有窗口。
原文 http://www.cnblogs.com/mfm11111/archive/2009/06/30/1514322.html 开发旺旺群发软件,难点及重要技术点分析(一) 一. ...
- 调用API函数,在窗口非客户区绘图(通过GetWindowDC获得整个窗口的DC,就可以随意作画了)
http://hi.baidu.com/3582077/item/77d3c1ff60f9fa5ec9f33754 调用API函数,在窗口非客户区绘图 GDI+的Graphics类里有个FromHdc ...
- 使用API函数EnumWindows()枚举顶层窗口
http://simpleease.blog.163.com/blog/static/1596085820052770290/ 要枚举Windows当前所有打开的顶层窗口,可使用Windows A ...
- Vb.net/VB 声明API函数实现父窗口功能
回想第一次敲机房收费.自己调用了api函数实现了父窗口及其子窗口最小化的功能.现在再次遇到,自己就在思考,能不能继续使用API函数呢?答案当然是Of Course! 事实上细致看两者并没有多大的差别. ...
- Delphi调用API函数获取Windows目录信息、获取System目录信息、获取Temp临时文件目录信息
var Str1, Str2: Array[..Max_Path]of Char;//开辟缓冲区 Str3: Array[..]of Char; begin GetWindowsDirectory(@ ...
- 调用API函数减少c#内存占用(20+m减至1m以下)
原文:调用API函数减少c#内存占用(20+m减至1m以下) c#虽然内置垃圾回收机制,但是并不能解决程序占用内存庞大的问题,如果我们仔细观察任务管理器,我们会发现一个程序如果最小化的时候,它所占用的 ...
- Delphi - Windows系统下,Delphi调用API函数和7z.dll动态库,自动把文件压缩成.tar.gz格式的文件
项目背景 应欧美客户需求,需要将文件压缩成.tar.gz格式的文件,并上传给客户端SFTP服务器. 你懂的,7-Zip软件的显著特点是文件越大压缩比越高,在Linux系统上相当于我们Windows系统 ...
- 实现:调用API函数ShowWindow()来隐藏窗口
只需要将相应代码复制即可. 代码如下: #include <iostream> #include <windows.h> int main() { HWND hDos; //声 ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
随机推荐
- MongoDB insert performance rapidly dropping
http://dba.stackexchange.com/questions/65554/mongodb-insert-performance-rapidly-dropping http://www. ...
- USB信号是什么类型的? 为什么在D+,D-处要接上拉下拉电阻呢,具体阻值要如何计算
USB协议要求的,1.5K上拉在D+时表示是全速设备,在D-表示不是全速设备有些方案里面(比如PNX5230)推荐D+/D-接下拉1M的电阻是为了提高数据传输稳定性的 ① usb有主从设备之分,主设 ...
- 基于新唐M0的XXTEA加密解密算法源码
/*-------------------------------------------------------------------------------------------------- ...
- C# System.AppDomain类
进程是存在独立的内存和资源的,但是AppDomain仅仅是逻辑上的一种抽象.一个process可以存在多个AppDomain.各个AppDomain之间的数据时相互独立的.一个线程可以穿梭多个AppD ...
- 基于jeasyui的遮罩扩展[修复链式bug]
说明和使用方法看下面代码,直接复制下面代码保存为js文件,引用即可. 遮罩效果从datagrid中提取,针对jquery进行优化. 下载地址(附Demo):http://pan.baidu.com/s ...
- linux 让root用户可以telnet
haproxy01:/root# cat /etc/securetty console vc/1 vc/2 vc/3 vc/4 vc/5 vc/6 vc/7 vc/8 vc/9 vc/10 vc/11 ...
- 使用docker打造spark集群
前提条件:安装好了docker,见我的另一篇博客,Docker安装 有两种方式, Spark官方repo里,docker文件夹下的脚本.官方的这个脚本封装很薄,尽可能把必要的信息展示出来. AMPLa ...
- CentOS 6.5 CodeBlocks::wxWidgets安装与配置
第一步, #yum install codeblocks codeblocks-contrib codeblocks-devel 第二步,到官方下载源码包,我下的是wxX11的3.0版的. #tar ...
- UESTC_秋实大哥与妹纸 2015 UESTC Training for Data Structures<Problem F>
F - 秋实大哥与妹纸 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 1500/1500KB (Java/Others) Submit ...
- struct2-json
一.JSON是什么? :JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解 析和生成.它基于JavaScript(Stan ...