#include <Windows.h>
#include <iostream>
#include <string> static BOOL CALLBACK enumchildWindowCallback(HWND hWnd, LPARAM lparam) {
int length = GetWindowTextLength(hWnd);
char * buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
std::string windowTitle(buffer); std::cout << hWnd << ": " << windowTitle << std::endl;
delete buffer;
return TRUE;
} int main()
{
HWND hwnd = (HWND)0x000D0DEE; //父窗口的句柄
EnumChildWindows(hwnd, enumchildWindowCallback, NULL); std::cin.ignore();
return 0;
}

拓展: 使用EnumWindows枚举窗口句柄(不包括子窗口)

#include <Windows.h>
#include <string>
#include <iostream> static BOOL CALLBACK enumchildWindowCallback(HWND hWnd, LPARAM lparam) {
int length = GetWindowTextLength(hWnd);
char* buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
std::string windowTitle(buffer); int n = (int)hWnd;
// Ignore windows if invisible or missing a title
// if (IsWindowVisible(hWnd) && length != 0) {
std::cout << n << ": " << windowTitle << std::endl;
// }
delete buffer;
return TRUE;
} static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM m) {
TCHAR _classbuf[255];
int length = GetWindowTextLength(hWnd);
char* buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
std::string windowTitle(buffer);
m = GetClassName(hWnd, _classbuf, 1024);
int n = (int)hWnd;
// Ignore windows if invisible or missing a title
// if (IsWindowVisible(hWnd) && length != 0) {
std::cout << n << ": " << windowTitle << std::endl;
// EnumChildWindows(hWnd, enumchildWindowCallback, m);
// }
return TRUE;
} int main()
{
std::cout << "Enmumerating windows..." << std::endl;
EnumWindows(enumWindowCallback, NULL); std::cin.ignore();
return 0; }
如果去掉EnumChildWindows(hWnd, enumWindowCallback, m)的注释,将会枚举所有的窗口

更新之后的版本:

#include <Windows.h>
#include <iostream>
#include <tchar.h> static BOOL CALLBACK enumchildWindowCallback(HWND hWnd, LPARAM lparam) {
TCHAR buffer[256] = {};
GetWindowText(hWnd, buffer, 256);
int n = (int)hWnd;
if (IsWindowVisible(hWnd))
{
RECT rc;
GetWindowRect(hWnd, &rc);
_tprintf(TEXT("0x%x : %s %d %d\n"), n, buffer, rc.right - rc.left, rc.bottom - rc.top);
}
return TRUE;
} static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM m) {
TCHAR buffer[256] = {};
GetWindowText(hWnd, buffer, 256);
int n = (int)hWnd;
if (IsWindowVisible(hWnd))
{
RECT rc;
GetWindowRect(hWnd, &rc);
_tprintf(TEXT("0x%x : %s %d %d\n"), n, buffer, rc.right - rc.left, rc.bottom - rc.top);
EnumChildWindows(hWnd, enumchildWindowCallback, m);
}
return TRUE;
} int main()
{
_tprintf(TEXT("Enmumerating windows..."));
EnumWindows(enumWindowCallback, NULL); return 0; }

win32-EnumChildWindows的使用的更多相关文章

  1. Microsoft Win32 to Microsoft .NET Framework API Map

    Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles   ...

  2. Delphi实现获取句柄并发送消息的方法(FindWindow、FindWindowEx、EnumChildWindows、SendMessage)

    Delphi实现获取句柄并发送消息的方法 本文以实例形式详细说明了Delphi获取句柄并发送消息的方法,具体用法说明如下: 查找另外一个窗口的句柄: handle := FindWindow(nil, ...

  3. C#[Win32&WinCE&WM]应用程序只能运行一个实例:MutexHelper

    前言 在开发应用程序时,通常只让程序运行一个实例.所以,就要判断程序是否已经运行. 下面是我自己在项目中使用到,封装好的帮助类.有 普通的 C# 应用程序 和 Windows CE 和 Windows ...

  4. java.lang.UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序。

    JNA 调用 dll 库时,保错: ///////////////// 通过 JNA 引入 DLL 库 //////////// /** * ID_FprCap.dll 负责指纹的采集, 指纹仪的初始 ...

  5. 初次认识 C# win32 api

    第一次接触win32api,刚开始的时候有点迷迷糊糊的. Windows API 就是windows应用程序接口. win api向上就是windows应用程序,向下就是windows操作系统核心. ...

  6. [老文章搬家] [翻译] 深入解析win32 crt 调试堆

    09 年翻译的东西. 原文见:  http://www.nobugs.org/developer/win32/debug_crt_heap.html 在DeviceStudio的Debug编译模式下, ...

  7. Virus.Win32.Virlock.b分析

    0x00 样本说明 分析样本是被0b500d25f645c0b25532c1e3c9741667的样本感染得到.感染前的文件是Tcpview.exe,一款windows网络连接查看工具. 感染前后文件 ...

  8. C#调用win32 api 操作其它窗口

    实现以下功能: 找到窗体 找到控件(也叫子窗体) 获取内容 获取位置 设置 位置 内容 鼠标点击 示范 1. 找窗体 以操作系统自带的计算器为例 string clWindow = "Cal ...

  9. cocos2d-x 从win32到android移植的全套解决方案

    引言:我们使用cocos2d-x引擎制作了一款飞行射击游戏,其中创新性地融入了手势识别功能.但是我们在移植过程中遇到了很多的问题,同时也发现网上的资料少而不全.所以在项目行将结束的时候,我们特地写了这 ...

  10. Git使用出错:Couldn‘t reserve space for cygwin‘s heap, Win32

    今天使用Git在命令行下更新代码遇到了问题,起初觉得是自己安装某软件导致冲突,从网上搜索了一下找到类似问题,成功解决问题. 错误信息如下: E:\storm-sql>git pull origi ...

随机推荐

  1. [转帖]PG-用户|角色管理

    https://www.cnblogs.com/binliubiao/p/14415203.html 1. 角色 ​ 决定发起连接的命令的初始访问权限.在PG中,角色和用户相当于是一样的对象.区别在于 ...

  2. [转帖]初识SkyWalking

    https://zhuanlan.zhihu.com/p/361579294 一.SkyWalking 是什么? 一个开源的可观测平台,用于从服务和云原生基础设施收集,分析, 聚合及可视化数据. Sk ...

  3. [转帖]iptables 执行清除命令 iptables -F 要非常小心的

    使用 /sbin/iptables -F 要小心,搞不好,你就马上同服务器断开连接了 以下是来自 http://wiki.ubuntu.org.cn/IptablesHowTo 上的说明 可以通过/s ...

  4. [转帖]012 Linux 搞懂用户权限升级 (sudo 和 su),包学会

    https://my.oschina.net/u/3113381/blog/5431540 Linux 系统中 root 账号通常用于系统的管理和维护,对操作系统的所有资源具有访问控制权限,当一个普通 ...

  5. Oracle 设置白名单过滤

    最近有一个需求  要求开发人员不能随便连接测试的数据库 又不想太过复杂,部分人还得进行连结. 查了下往上是有方案的: 就是 TCP_VALIDNODE_CHECKING 参数 解决方法和说明如下 来源 ...

  6. fiddler如何抓取https请求

    pc端browse 1.打开下载好的fiddler,点击tools选择options后进入https tab下,勾选Decrypt  HTTPS CONNECTS 和Ignore server cer ...

  7. 学习React中的jsx-保证你看的明明白白

    安装react的脚手架 1==>行 npx create-react-app myreactdemo01 解释一下: npx create-react-app 你的项目名称 npx create ...

  8. 【记录一个问题】vm-select和vm-storage均无法做并行查询

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 看我提的这个issue: need parallel qu ...

  9. 在C#或python中使用xpath解析xml

    记几个笔记 文件后缀不一定要.xml,可以是任意后缀,只要内容是符合xml和格式即可解析出来 文件编码需要是utf-8,python和c#都需要,或者xml文件头有这样一句:<?xml vers ...

  10. Vue双向数据绑定原理-下

    Vue双向数据绑定原理-下这一篇文章主要讲解Vue双向数据绑定的原理,主要是通过Object.defineProperty()来实现的,这里我们手写Vue双向数据绑定的原理. 首先我提出一个需求,我的 ...