#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. [转帖]create table INITRANS参数分析

    https://www.modb.pro/db/44701 1. 内容介绍 Oracle数据库create table时使用INITRANS参数设置数据块ITL事务槽的数量,确保该数据块上 并发事务数 ...

  2. [转帖]Nginx反向代理中使用proxy_redirect重定向url

    https://www.cnblogs.com/kevingrace/p/8073646.html 在使用Nginx做反向代理功能时,有时会出现重定向的url不是我们想要的url,这时候就可以使用pr ...

  3. [转帖]Linux-计算毫秒数

    https://www.cnblogs.com/yeyuzhuanjia/p/15822653.html date +%s返回自划时代以来的秒数. date +%s%N返回秒数+当前纳秒数. 因此,e ...

  4. [转帖]陈巍谈芯:NLP里比BERT更优秀的XLNet长什么样?

    https://zhuanlan.zhihu.com/p/447836322 ​ 目录 收起 一.XLNet的优势 1)独得AR与AE两大绝学 2)集成了Tansformer-XL 二.XLNet的结 ...

  5. 查看dmesg 里面部分内容的精确时间

    for i in `dmesg |grep "stuck for" |awk '{print $1}' |awk -F "." '{print $1}' |aw ...

  6. js中计算一个时间点加上一个时间段后的时间

    function aa(a,b){ console.log(111,a,b) var nd = new Date(Date.parse(a.replace(/-/g, "/"))) ...

  7. Registration Authority 简介

    RA 功能简介 在公共密钥基础设施(PKI)中,CA(Certificate Authority,证书颁发机构)系统的RA(Registration Authority,注册机构)是PKI体系结构的重 ...

  8. 【学习日志】Java基本数据类型的自动装箱和拆箱

    // 测试代码 public static void main(String[] args) { Integer a = 1; Integer b = 2; Integer c = 3; Intege ...

  9. 你的代码已被埋在北极冰雪之下,保存千年——GitHub北极代码保险库

    GitHub存档计划:北极代码保险库 在2019 GitHub 宇宙大会(GitHub Universe 2019)上,他们提到了一个问题,1000年后的软件会是什么样?人类会是什么样子?对此我们只能 ...

  10. 9.4 Windows驱动开发:内核PE结构VA与FOA转换

    本章将继续探索内核中解析PE文件的相关内容,PE文件中FOA与VA,RVA之间的转换也是很重要的,所谓的FOA是文件中的地址,VA则是内存装入后的虚拟地址,RVA是内存基址与当前地址的相对偏移,本章还 ...