如何遍历窗体上的元素(控件、组件),并且判断是何控件:如是CEdit,还是CComboBox,还是CListBox等等.

解决方案 »

  1.   

    枚举子窗口
    BOOL EnumChildWindows(
        HWND hWndParent,
        WNDENUMPROC lpEnumChildFunc,
        LPARAM lParam
    );在 EnumChildFunc 中 使用 (CWnd::FromHandle(hWnd))->IsKindof(RUNTIME_CLASS(CEdit));
      

  2.   

    //this is my example,maybe help you
    EnumChildWindows(hwnd,EnumChildProc,0);//hwnd is the parent window handleBOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) 
    {
    char temp[100];
    memset(temp,0,100);
    GetClassName(hwndChild, temp, sizeof(temp));
    long l =GetWindowLong(hwndChild, GWL_STYLE); if(!strcmp(temp,_T("Edit")))// Edit输入框
    {
    if(l & ES_READONLY)
    {
                            ...
    }
    if(l & ES_PASSWORD)   //普通密码输入框
    {
                           ..
    }
    }
    if(!strcmp(temp,_T("Static")) )
    {
                 ..
    }
    return TRUE;
    }
      

  3.   

    HWND FindWindowEx(
      HWND hwndParent,      // handle to parent window
      HWND hwndChildAfter,  // handle to a child window
      LPCTSTR lpszClass,    // pointer to class name
      LPCTSTR lpszWindow    // pointer to window name
    );
     
      

  4.   

    CWnd* pWnd = GetWindow(GW_CHILD);
    while(pWnd)
    {
        pWnd = pWnd ->GetWindow(GW_HWNDNEXT);
    }
    这个很简单,记得给粉啊?
      

  5.   


    EnumChildWindows好久不来了,熟人都哪去了?