Use the function EnumChildWindows. This function uses a callback. I already explained this a few threads ago concerning an other function that uses callback.
I test the following code in a dialog bow where I put a button called IDC_GET and several other controls. The OnGet() is the handler of this button.
Here it is:
void CEnumChildDlg::OnGet()
{
HWND hwnd = this->GetSafeHwnd();
if ( !EnumChildWindows( hwnd, EnumChildProc, ( LPARAM) hwnd))
AfxMessageBox( "Problem getting Child Windows"
}
The first parameter is the handle of the parent window. The third parameter is the parameter that is passed to the callback function. In this case, this is the same handle. It could be used to transfer data back to the calling process. Remember that a static function accesses only static members, so passing the handle of the calling process is a mean to exchange data between a static and a non-static member. See the code below
Remember thet a callback must be declared static.
As this:
In this simple example, I'll just display the control id in the debug window ...
BOOL CALLBACK CEnumChildDlg::EnumChildProc( HWND hwnd, LPARAM lParam)
{
// Get a Pointer to the window found by EnumChildWindows function (first param)
In this case you update a memmber of the class CEnumChildDlg from within the callback function. Of course, if you need to transfer the id of all child windows, you'll use an array or a list...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.