BOOL CAllwindowsDlg::EnumWindowsProc(HWND hWnd, LPARAM lParam){ //be sure the current window is visible if(::GetWindowLong(hWnd,GWL_STYLE)& WS_VISIBLE) { m_hwndFind[m_num] = hWnd;//record the HWND handle into array m_num++;//count start } return 1;}
11
void CAllwindowsDlg::OnButton3() { m_num = 0; m_list.ResetContent(); ::EnumWindows(CAllwindowsDlg::EnumWindowsProc,NULL); for(int i = 0;i <=m_num;i++) { HWND m_wnd = m_hwndFind[i]; ::GetWindowText(m_wnd,m_store,128); ::GetClassName(m_wnd,m_strClass,MAX_PATH-1); m_winname[i] = m_store; sprintf(m_name,"(%d)标题名称:",i); strcat(m_name,m_store); strcat(m_name," 类名称:"); strcat(m_name,m_strClass); m_list.AddString(m_name); } }