方法一:
m_hWnd代表对话框window
HWND hwndChild = GetWindow( m_hWnd , GW_CHILD );
while( hwndChild )
{
hwndChild = GetWindow( hwndChild , GW_HWNDNEXT );
}
GetWindow
The GetWindow function retrieves a handle to a window that has the specified relationship (Z order or owner) to the specified window.
HWND GetWindow(
HWND hWnd, // handle to original window
UINT uCmd // relationship flag
);
Parameters
hWnd
Handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter.
uCmd
Specifies the relationship between the specified window and the window whose handle is to be retrieved.
This parameter can be one of the following values: Value Meaning
GW_CHILD The retrieved handle identifies the child window at the top of the Z order,
if the specified window is a parent window; otherwise, the retrieved handle is NULL.
The function examines only child windows of the specified window.
It does not examine descendant windows.
GW_HWNDNEXT The retrieved handle identifies the window below the specified window in the Z order.
If the specified window is a topmost window, the handle identifies the topmost window below
the specified window. If the specified window is a top-level window,
the handle identifies the top-level window below the specified window.
If the specified window is a child window, the handle identifies the sibling window
below the specified window.
....
请查看msdn获得更多信息
方法二:
vector<HWND> hwv;
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
TCHAR buf[100];
::GetClassName( hwnd, (LPTSTR)&buf, 100 );
if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ) /
{
*(HWND*)lParam = hwnd;//子窗口句柄哦
hwv.push_back( hwnd ); //收集所有的字窗口句柄
//return FALSE;
}
else
return TRUE;
};
//You can store the interface pointer in a member variable
//for easier access
void CDlg::OnGetDocInterface()
{
HWND hWnd = this->m_hWnd;
if ( hWnd != NULL )
{
HWND hWndChild=NULL;
// Get 1st document window
/*
系统会查找hWnd的字窗口,然后对每一字窗口都要调用函数EnumChildProc
并把字窗口的句柄欻给函数EnumChildProc,另外还会把参数(LPARAM)&hWndChild 传给EnumChildProc,
所以每一个回调EnumChildProc,传进去的参数有一个都是相同的(即 (LPARAM)&hWndChild).
另外一个参数则总是不同(即字窗口句柄).
只有当 对所有字窗口都进行回调函数的调用或者回调函数返回FLASE,EnumChildWindows才会返回.
*/
::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
if ( hWndChild )
{
} // else document not ready
}
}
EnumChildWindows
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
);
....
请查看msdn获得更多信息