方法一:
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獲得更多資訊