GetWindow()可以得到一个窗口的子窗口,edit box也是一个子窗口

解决方案 »

  1.   

    hwndEdit=GetWindow(hwnd,GW_CHILD);
    谁说GetDlgItem不行?看看msdn
    GetDlgItem
    The GetDlgItem function retrieves a handle to a control in the specified dialog box. HWND GetDlgItem(
      HWND hDlg,       // handle to dialog box
      int nIDDlgItem   // control identifier
    );
    Parameters
    hDlg 
    [in] Handle to the dialog box that contains the control. 
    nIDDlgItem 
    [in] Specifies the identifier of the control to be retrieved. 
    Return Values
    If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.Res
    You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifier (as specified by the hMenu parameter in the CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window. Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winuser.h; include Windows.h.
      Library: Use User32.lib.See Also
    Dialog Boxes Overview, Dialog Box Functions, CreateWindow, CreateWindowEx, GetDlgItemInt, GetDlgItemText Built on Thursday, October 12, 2000Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winuser.h; include Windows.h.
      Library: Use User32.lib.
    See Also
    Dialog Boxes Overview, Dialog Box Functions, CreateWindow, CreateWindowEx, GetDlgItemInt, GetDlgItemText 
    明明写着not just dialog box。不过这个GetDlgItem是WIndows API,不是CWnd的成员函数。
    不过就算是CWnd成员函数,也行呀。
    CWnd::GetDlgItem  
    CWnd* GetDlgItem( int nID ) const;void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;Return ValueA pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL. The returned pointer may be temporary and should not be stored for later use.ParametersnIDSpecifies the identifier of the control or child window to be retrieved.phWndA pointer to a child window.ResRetrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.Example// uses GetDlgItem to return a pointer to a user interface control
    CEdit* pBoxOne;
    pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT1);
    GotoDlgCtrl(pBoxOne);CWnd Overview |  Class Members |  Hierarchy ChartSee Also   CWnd::GetWindow, CWnd::GetDescendantWindow, CWnd::GetWindow,::GetDlgItem
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources. 
    上边的帮助说了,Retrieves a pointer to the specified control or child window in a dialog box or other window.
    我只用过API的GetDlgItem,没用过CWnd::GetDlgItem,你可以试试。
    要是用GetWindow,那就复杂一些。
    hwndChild=GetWindow(hwndParent,GW_CHILD);
    while (GetWindowLong(hwndChild,GWL_ID)!=ID_EDITBOX)
    {
        hwndChild=GetWindow(hwndChild,GWL_HWNDNEXT);
        if (GetWindow(hwndChild,GW_OWNER)!=hwndParent)
        {
            hwndChild=NULL;
            break;
        }
    }