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之 ...
随机推荐
- [转载] 50个Android开发人员必备UI效果源码
好东西,多学习! Android 仿微信之主页面实现篇Android 仿微信之界面导航篇Android 高仿QQ 好友分组列表Android 高仿QQ 界面滑动效果Android 高仿QQ 登陆界面A ...
- TEA encryption with 128bit key
If anyone needs some basic encryption in software, here's one solution. This TEA implementation fits ...
- QPainter就是手里的作图工具,只需要三洋东西:笔(颜色,宽度,样式),字体(写字),刷子(大面积作画),这里有三个典型例子
设置笔和字体以后,就可以写字了: void MainWindow::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter ...
- perl return和break
zjzc01:/root/test# cat a3.pl sub mask { my $n=shift; my $j =100; for ($i = 1;$i <= 5;$i++){ print ...
- Linux下程序崩溃,ulimit,coredump,gdbserver
操作系统:Ubuntu10.04 前言: 在程序崩溃后,如何快速定位问题. 以下方法适用于开发调试阶段,不太适用成品. 本文着眼于嵌入式,PC方面更简单. 核心:gdbserv ...
- Course Schedule 解答
Question There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may ...
- vector迭代器失效的一种情形
使用过STL的人都应该知道关于迭代器失效的原理,这里以后vector迭代器失效为例: 第一种:当插入一个元素到vector中,如果插入后容器已满,那么容器将新开辟一块内存区域,然后 将原内存中的数据拷 ...
- MongoDB 复制
副本集:简单说,副本集就是有自动故障恢复功能的主从集群.主从集群和副本集最为明显的区别:副本集没有固定的“主节点”.整个集群会选出一个主节点.当其不能工作时,变更到其他节点.二者看起来非常相似:副本集 ...
- HDU 4649 Professor Tian
Professor Tian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- 很少人知道的office专用卸载工具
Microsoft Office是微软公司开发的一套基于 Windows 操作系统的办公软件套装.常用组件有 Word.Excel.Powerpoint等.当我们不需要再用了或者想安装旧版本的话,首先 ...