private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);

        [DllImport("user32.dll", ExactSpelling = true)]
private static extern bool EnumChildWindows(IntPtr hwndParent, WNDENUMPROC lpEnumFunc, int lParam); [DllImport("user32.dll")]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);
//[DllImport("user32.dll")]
//private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
public struct WindowInfo
{
public IntPtr hWnd;
public string szWindowName;
public string szClassName;
} private List<WindowInfo> EnumChildWindowsCallback(IntPtr handle, string name, string classname)
{
List<WindowInfo> wndList = new List<WindowInfo>();
EnumChildWindows(handle,delegate(IntPtr hWnd, int lParam)
{
WindowInfo wnd = new WindowInfo();
StringBuilder sb = new StringBuilder();
//get hwnd
wnd.hWnd = hWnd;
//get window name
GetWindowTextW(hWnd, sb, sb.Capacity);
wnd.szWindowName = sb.ToString();
//get window class
GetClassNameW(hWnd, sb, sb.Capacity);
wnd.szClassName = sb.ToString();
//add it into list
wndList.Add(wnd);
return true;
},);
return wndList.Where(it => it.szWindowName == name && it.szClassName == classname).ToList();
} public List<WindowInfo> GetAllDesktopWindows(string name,string classname)
{
List<WindowInfo> wndList = new List<WindowInfo>(); //enum all desktop windows
EnumWindows(delegate(IntPtr hWnd, int lParam)
{
WindowInfo wnd = new WindowInfo();
StringBuilder sb = new StringBuilder();
//get hwnd
wnd.hWnd = hWnd;
//get window name
GetWindowTextW(hWnd, sb, sb.Capacity);
wnd.szWindowName = sb.ToString();
//get window class
GetClassNameW(hWnd, sb, sb.Capacity);
wnd.szClassName = sb.ToString();
//add it into list
wndList.Add(wnd);
return true;
}, ); return wndList.Where(it => it.szWindowName == name && it.szClassName ==classname ).ToList();
}

c# 列举所有窗口和子窗口的更多相关文章

  1. HTML中IFrame父窗口与子窗口相互操作

    一.Iframe篇 //&&&&&&&&&&&&&&&&&&am ...

  2. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  3. js window.open() 父窗口与子窗口的互相调用(未必有用)

    javascript 父窗口与子窗口的互相调用 <html> <head></head> <body> 主要实现父子关系的页面 window.opene ...

  4. 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 //&&&&&&&&&&&&&&&&&&a ...

  5. windows 编程 —— 子窗口 与 子窗口控件

    目录: 子窗口与主窗口的交互 子窗口控件 按钮类别 button 滚动条类别 scrollbar 静态类别  static 编辑框类别 edit 清单方块 listbox 子窗口与主窗口的交互 创建窗 ...

  6. windows窗口分析,父窗口,子窗口,所有者窗口

    (本文尝试通过一些简单的实验,来分析Windows的窗口机制,并对微软的设计理由进行一定的猜测,需要读者具备C++.Windows编程及MFC经验,还得有一定动手能力.文中可能出现一些术语不统一的现象 ...

  7. #js window.open() 父窗口与子窗口的互相调用【转】

    未完整版 javascript 父窗口与子窗口的互相调用 a.html 父页面 <HTML> <HEAD> <meta http-equiv="content- ...

  8. iframe父窗口和子窗口之间的调用

    1>父窗口获取子窗口 js方法 document.getElementById('if1').contentWindow.document: window.frames["if1&qu ...

  9. QT 主窗口和子窗口相互切换示例

    QT 主窗口和子窗口相互切换示例 文件列表: SubWidget.h #ifndef SUBWIDGET_H #define SUBWIDGET_H #include <QtWidgets/QW ...

  10. 总结js(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    http://hi.baidu.com/yashua839/blog/item/131fdb2fe547ef221f3089af.html一.Iframe 篇 //&&&&am ...

随机推荐

  1. MAC 安装j2ee.sh的办法

    It says it needs the DISPLAY variable set - what do I need to set it to? Instead of saying: ./java_e ...

  2. oracle pl/sql split函数

    在软件开发过程中程序员经常会遇到字符串的拼接和拆分工作. 以java开发为例: 前台传入字符串拼接形式的一个JSON数据,如:"1001,1002,1003",这可能代表了一组序号 ...

  3. apache 指定的网络名不再可用 原因及解决方法

    1.出现问题状况: 出现问题网站:http://www.ayyzz.cn/ 前段时间作文大全网出现有时候比较慢,有时候“找不到网页”404错误:另外在error.log里也报错: [Mon May 0 ...

  4. REDIS源码中一些值得学习的技术细节02

    Redis中散列函数的实现: Redis针对整数key和字符串key,采用了不同的散列函数 对于整数key,redis使用了 Thomas Wang的 32 bit Mix Function,实现了d ...

  5. 解决PKIX(PKIX path building failed) 问题 unable to find valid certification path to requested target

    最近在写java的一个服务,需要给远程服务器发送post请求,认证方式为Basic Authentication,在请求过程中出现了 PKIX path building failed: sun.se ...

  6. SQL关于limit的用法

    SELECT * FROM table  LIMIT [offset,] rows | rows OFFSET offset    在我们使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时 ...

  7. sqlserver2012 表分区

    无论是新建数据库,还是现有的问题,都可以执行表分区的操作. 1.在数据库中点鼠标右键点击属性,在选择页,选中文件栏,在数据库文件列表中,可以看到现有的数据库文件逻辑名称.文件类型.初始大小.保存位置等 ...

  8. 省市二级联动(原生JS)

    代码如下: <html> <head> <meta charset="UTF-8"> <title>省市二级联动</title ...

  9. Linux 如何安装memcache?

    原有memcache所在机器损坏,需要在新的Linux机器上安装memcache,具体步骤如下: 1.使用Linux机器的root权限登陆 2.安装libevent 下载地址:http://libev ...

  10. img 是内联元素

    图片是内联元素 ,同时是内联替换元素(替换元素是能设置宽和高的) 取消图片的magin display:block;(一般初始化标签中会把图片设置成块状) replaced element <i ...