EnumWindows遍历窗口

作者: 吴杰 分类: 编程 发布时间: 2015-03-01 21:41

EnumWindows遍历窗口

#include <vector>
using namespace std;


vector<HWND > m_hWnds;
BOOL EnumWindowsProc(HWND hWnd , LPARAM lParam )
{
    if (::GetWindowLong( hWnd, GWL_STYLE)& WS_VISIBLE)
    {
        char szClassName[128] = { 0 };
        if (::GetClassNameA( hWnd, szClassName, 128) != 0)
        {
            if (strcmp( "3DSMAX", szClassName) == 0)
            {
                m_hWnds.push_back( hWnd);
            }
        }

    }
    return TRUE;
}

int Get3dmaxWndCount()
{
    m_hWnds.clear();
    ::EnumWindows((WNDENUMPROC)EnumWindowsProc, NULL);

    return (int)m_hWnds.size();
}