rt

解决方案 »

  1.   

    The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE. BOOL EnumChildWindows(
      HWND hWndParent,         // handle to parent window
      WNDENUMPROC lpEnumFunc,  // pointer to callback function
      LPARAM lParam            // application-defined value
    );
      

  2.   

    HWND hWnd = GetWindow(hWndParent, GW_CHILD);while (hWnd)
    {
        // Do something here ...     hWnd = GetWindow(hWnd, GW_HWNDNEXT);
    }其中的 API 用 MFC CWnd::GetWindow 代替也可以
      

  3.   

    struct MyControlSize first;
    CSizeDlg *parent;
    struct MyRect pr;
    int ttt;
    int ppp;
    BOOL CALLBACK
    EnumChildProc( HWND hwnd, LPARAM lParam )
    {
    struct MyControlSize *t;
    t = &first;
    while( t->next )
    {
    t = t->next;
    }
    t->next = new struct MyControlSize;
    t->next->next = NULL;
    t->next->h = hwnd;
    t->next->last = t;
    RECT r;
    ::GetWindowRect( hwnd, &r );
    t->next->r.left = ( double )r.left;
    t->next->r.top = ( double )r.top;
    t->next->r.right = ( double )r.right;
    t->next->r.bottom = ( double )r.bottom;
    return 1;
    }BOOL CSizeDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    parent = this;
    EnumChildWindows( this->m_hWnd, EnumChildProc, 0 );
    RECT r;
    RECT rr;
    GetClientRect( &r );
    GetWindowRect( &rr );
    ppp = ( rr.right - r.right ) / 2;
    ttt = rr.bottom - r.bottom - ppp;
    pr.left = ( double ) r.left;
    pr.top = ( double )r.top;
    pr.right = ( double )r.right;
    pr.bottom = ( double )r.bottom;
    //Invalidate();
    return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  4.   

    各位,如果有的控件不是从CWnd继承来的怎么办?
      

  5.   

    可以啊
    既然EnumChildWindows()、GetWindow()是Windows API,它当然不会限定要MFC的类
      

  6.   

    JennyVenus的程序不错,但不能枚举所有控件。
    在EnumWindowProc函数的前面加一句:
    EnumChildWindows(hwnd, EnumWindowProc, 0);