前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >c++ 遍历桌面所有窗口/遍历一个窗口下的所有窗口

c++ 遍历桌面所有窗口/遍历一个窗口下的所有窗口

作者头像
用户7886150
修改2021-02-19 15:42:39
1.9K0
修改2021-02-19 15:42:39
举报
文章被收录于专栏:bit哲学院

参考链接: C++ wcscmp()

//遍历一个窗口下的所有子窗口

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) 

{

    LPWSTR lpString = (LPWSTR)malloc(1024 * sizeof(WCHAR));

    LPWSTR ClassString = (LPWSTR)malloc(1024 * sizeof(WCHAR));

    GetWindowText(hwnd, lpString, 1024);

    GetClassName(hwnd, ClassString, 1024);

    if (wcscmp(ClassString, _T("Edit"))==0) {

        Ghwnd[i] = hwnd;

        i++;

    }

    //wprintf(L"%s\n", lpString);

    return true;

}

void main()

{

    HWND hWnd= ::FindWindow(_T("TWINCONTROL"), _T("穿越火线"));

    EnumChildWindows(hWnd, EnumChildProc, NULL);

/*

 * 回调函数, 保存窗口标题信息

 */

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) // 回调函数

{

   TCHAR szTitle[200];

   TCHAR szClass[200];

   GetWindowText(hwnd, szTitle, sizeof(szTitle) / sizeof(TCHAR)); // 获取窗口名称

   GetClassName(hwnd, szClass, sizeof(szClass) / sizeof(TCHAR)); // 窗口类

   if (szTitle[0] != '\0' && IsWindowVisible(hwnd)) { // 判断窗口标题不为空,并且窗口可见

       strList.push_back(szTitle); // 添加到临时list中

   }

   return TRUE;

}

/**

 * 查找窗口

 */

void main()

{

    strList.clear();

    m_list.ResetContent();

    EnumWindows(EnumWindowsProc, 0); // 枚举窗口

    /* 将list中的值付给m_list控件展示 */

    LISTSTR::iterator i;

    for (i = strList.begin(); i != strList.end(); i++){

        m_list.AddString(*i);

    }

}

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档