How to get all the child controls of a window

16 10 2009

Description

 

 

There are two types windows or controls we will deal with in our application. A parent window contains many number of child controls. How shall we enumerate all the child controls of a window. That means control ID, text etc etc…

HowCanIDoIt1

 

 

The EnumChildWindows function enumerates all the child windows/controls belongs to a specified window. This function invokes a application defined CALLBACK function until the last child control is enumerated or the function returns false.

MyCodeSnippet

 

 

void OnEnumerateChildCtrls()
{
   EnumChildWindows(this->m_hWnd,EnumWindowsProc, 0);
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
   TCHAR buff[256];
   ::GetWindowText(hwnd,(LPSTR)buff, 255);
   int nCtrlID = ::GetDlgCtrlID(hwnd);
   return TRUE;
}
void OnEnumerateChildCtrls()
{
   EnumChildWindows(this->m_hWnd,EnumWindowsProc, 0);
}
 
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
   TCHAR buff[256];
   ::GetWindowText(hwnd,(LPSTR)buff, 255);
   int nCtrlID = ::GetDlgCtrlID(hwnd);

   return TRUE;
}

mynote9

 

 

If a child window creates its own child controls, EnumChildWindows enumerates that also.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: