调用EnumChildWindows依次枚举,根据窗口的Class,判断类型。MSDN中的来自:
#define ID_FIRSTCHILD  100 
#define ID_SECONDCHILD 101 
#define ID_THIRDCHILD  102 
 
LONG APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 

    RECT rcClient; 
    int i; 
 
    switch(uMsg) 
    { 
        case WM_CREATE: // creating main window  
 
            // Create three invisible child windows. 
 
            for (i = 0; i < 3; i++) 
            { 
                CreateWindowEx( 
                    0, 
                    "ChildWClass", 
                    (LPCTSTR) NULL, 
                    WS_CHILD | WS_BORDER, 
                    0,0,0,0, 
                    hwnd, 
                    (HMENU) (int) (ID_FIRSTCHILD + i), 
                    hinst, 
                    NULL); 
            }
 
            return 0; 
 
        case WM_SIZE:   // main window changed size 
 
            // Get the dimensions of the main window's client 
            // area, and enumerate the child windows. Pass the 
            // dimensions to the child windows during enumeration. 
 
            GetClientRect(hwnd, &rcClient); 
            EnumChildWindows(hwnd, EnumChildProc, 
                (LPARAM) &rcClient); 
            return 0; 
        // Process other messages. 
 
    } 
    return DefWindowProc(hwnd, uMsg, wParam, lParam); 

 
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) 

    LPRECT rcParent; 
    int i, idChild; 
 
    // Retrieve the child-window identifier. Use it to set the 
    // position of the child window. 
 
    idChild = GetWindowLong(hwndChild, GWL_ID); 
 
    if (idChild == ID_FIRSTCHILD) 
        i = 0; 
    else if (idChild == ID_SECONDCHILD) 
        i = 1; 
    else 
        i = 2; 
 
    // Size and position the child window.  
 
    rcParent = (LPRECT) lParam; 
    MoveWindow(hwndChild, 
        (rcParent->right / 3) * i, 
        0, 
        rcParent->right / 3, 
        rcParent->bottom, 
        TRUE); 
 
    // Make sure the child window is visible. 
 
    ShowWindow(hwndChild, SW_SHOW); 
 
    return TRUE; 

解决方案 »

  1.   

            CWnd* pWnd = GetWindow(GW_CHILD);
            if (pWnd != NULL)
            {
                ASSERT(pWnd->GetWindow(GW_HWNDNEXT) == NULL);
            }
      

  2.   

    我的这段代码有什么不正确的吗?为什么不能显示出控件的ID?
       CWnd *pwnd=GetDlgItem(GW_CHILD);
       CString sCtrlName;
       if(pwnd!=NULL)
       {
       pwnd=pwnd->GetNextWindow(GW_HWNDNEXT);
       sCtrlName.Format("%s",pwnd->GetDlgCtrlID());
       MessageBox(sCtrlName);
       } 
      

  3.   

     if(pwnd!=NULL)-> while(pwnd!=NULL)
      

  4.   

    改成
    ?
      CWnd *pwnd=GetDlgItem(GW_CHILD);
      CString sCtrlName;
      while(pwnd!=NULL)
      {
      pwnd=pwnd->GetNextWindow(GW_HWNDNEXT);
      sCtrlName.Format("%s",pwnd->GetDlgCtrlID());
      MessageBox(sCtrlName);
      } 
    以后还是不正确。
      

  5.   

      CWnd *pwnd=GetDlgItem(GW_CHILD);
      CString sCtrlName;
      while(pwnd!=NULL)
      {
      sCtrlName.Format("%s",pwnd->GetDlgCtrlID());
      MessageBox(sCtrlName);
    pwnd = pwnd->GetNextWindow();
      } 
      

  6.   

    还是不对,当执行至while(pwnd!=NULL)的时候就执行条件外面的语句去了。
    在debug窗口中pwnd的value=0x00000000{CWnd hWnd=???}
      

  7.   

    一个child都没有?? 是什么意思?
      

  8.   

    CWnd *pwnd=GetDlgItem(GW_CHILD);
    pwnd=NULL??
      

  9.   

    用GetWindow(GW_CHILD)!
    仔细看一下GetDlgItem()的解释吧!