CWnd* pWnd = GetTopWindow(); while(pWnd!=NULL) { int i = pWnd->GetDlgCtrlID(); CString str; str.Format("ID是:%d", i); //pWnd->SetWindowText(str); if(i!=-1) MessageBox(str); pWnd = pWnd->GetNextWindow(); }