#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. [转帖]DBWR与LGWR的写入机制

    https://www.jianshu.com/p/6c87cb6cd320 读与写是每个数据库提供的最基本的功能.当数据库中出现第一个进程时,总免不了要将数据从磁盘上加载到内存中,一次数据库的物理I ...

  2. [转帖]nginx配置默认首页(index.html index.htm)全流程(包含遇到问题的解决)

    https://www.cnblogs.com/tujietg/p/10753041.html#:~:text=%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%9 ...

  3. [转帖]grafana 连接 influxdb 1.x 和 2.x

    文章目录 一.安装 influxdb Ⅰ.docker 安装 二.常用操作 Ⅰ.influxdb 1.x版本添加用户认证 Ⅱ.influxdb 2.x 使用命令行 Ⅲ.CLI 配置token Ⅴ.CL ...

  4. [转帖]sendfile“零拷贝”、mmap内存映射、DMA

    https://www.jianshu.com/p/7863667d5fa7 KAFKA推送消息用到了sendfile,落盘技术用到了mmap,DMA贯穿其中. 先说说零拷贝 零拷贝并不是不需要拷贝, ...

  5. [转帖]nacos开启强鉴权

    注意 Nacos是一个内部微服务组件,需要在可信的内部网络中运行,不可暴露在公网环境,防止带来安全风险. Nacos提供简单的鉴权实现,为防止业务错用的弱鉴权体系,不是防止恶意攻击的强鉴权体系. 如果 ...

  6. 部署于K8S集群上面应用性能影响点推测

    前言 本人2017年第一次接触K8S. 中间断断续续学习K8S相关的内容. 但是最近一年,几乎没太有学习. 因为之前学习了四五年, 一直以为产品马上要用 结果一直被浇冷水. 去年开始学乖了. 不这么搞 ...

  7. 使用linux上面powershell安装vm powercli 连接vcenter 通过计划任务自动创建部分虚拟机的快照以及自动清理过期快照的办法

    经过一晚上的折腾, 终于验证出来一个非常简单的方法. 也比较好理解和使用. 这里简单记录一下: 使用linux上面powershell安装vm powercli 连接vcenter 通过计划任务自动创 ...

  8. svn把文件日期设置为最后提交的时间

    在使用svn进行checkout或update时,我想让文件的日期为提交那时的日期,这要怎样做? 说明:我是在windows下使用TortoiseSVN进行操作的 方法1.修改config [misc ...

  9. Pytest 源码解读 [1] - [pluggy] 核心设计理念浅读

    背景: Pytest 是一个功能强大的 Python 测试框架,它使用了一个名为 "pluggy" 的插件系统来扩展其功能.在 Pytest 的源码中,pluggy 模块负责实现插 ...

  10. TienChin 渠道管理-添加渠道

    在我们平时新建一个全新的 Java 类,这个类需要存放的包不存在,可以使用如下的方式进行创建: 含义就是说,将 ChannelVO 这个类放在 vo 这个包当中,如果存在则不创建,存在就将新建的类放入 ...