#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. [转帖]OutOfMemory自动重启程序

    OutOfMemory以后程序已经假死,无法再提供服务,最好的做法是dump内存,发送警告,然后重启服务 我的方案:利用at命令延迟启动 但有一个问题,at最多支持分钟操作,也就是说要1分钟以后才能启 ...

  2. 源码补丁神器—patch-package

    一.背景 vue项目中使用 vue-pdf第三方插件预览pdf,书写业务代码完美运行,pdf文件内容正常预览无问题.后期需求有变,业务需求增加电子签章功能.这个时候pdf文件的内容可以显示出来,但是公 ...

  3. 通过dotnet-dump分析生产环境docker容器部署的应用问题

    首先找到对应的docker id并exec进去,然后执行命令并更新apt包+下载procps和wget用于等下拉取dotnet-dump和查看线程 sed -i -e "s@deb.debi ...

  4. 深度学习应用篇-计算机视觉-语义分割综述[5]:FCN、SegNet、Deeplab等分割算法、常用二维三维半立体数据集汇总、前景展望等

    深度学习应用篇-计算机视觉-语义分割综述[5]:FCN.SegNet.Deeplab等分割算法.常用二维三维半立体数据集汇总.前景展望等 语义分割综述(semantic segmentation) 1 ...

  5. 5.1 Windows驱动开发:判断驱动加载状态

    在驱动开发中我们有时需要得到驱动自身是否被加载成功的状态,这个功能看似没啥用实际上在某些特殊场景中还是需要的,如下代码实现了判断当前驱动是否加载成功,如果加载成功, 则输出该驱动的详细路径信息. 该功 ...

  6. C++ Boost库 操作日期与时间

    Boost库中默认针对日期与时间的操作库分为,timer,progress_timer,date_time这几类,如下是一些常用的使用方法总结. timer库 #include <iostrea ...

  7. ntp.conf详解

    linux系统的ntp.conf文件默认保存在/etc/ntp.conf 版本: [root@dsview ntpstats]# cat /etc/redhat-release CentOS rele ...

  8. 详细了解Transformer:Attention Is All You Need

    1. 背景 在机器翻译任务下,RNN.LSTM.GRU等序列模型在NLP中取得了巨大的成功,但是这些模型的训练是通常沿着输入和输出序列的符号位置进行计算的顺序计算,无法并行. 文中提出了名为Trans ...

  9. 如果在循环中不改变vector的大小,C++编译器是否会将.size()优化为常数?

      在C++中,可以使用以下代码计算vector<int>中所有元素的和: vector<int> v = {1, 3, 7, 9}; sums = 0; for (int i ...

  10. 零基础入门Vue之皇帝的新衣——样式绑定

    回顾 大致掌握了上一节的 插值语法 我已经可以把想要的数据显示到页面上,并且仅需要修改变量,页面就会跟着实时改变 但如果对于已经熟悉前端的人来说,单单有数据还是不太行,还需要css对数据进行样式的修饰 ...