views:

59

answers:

3

Hello All,

I use EnumChildWindows to get all the Child windows from the main HWND window , But i would like to get only the first child of the given HWND window.

BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam)
{
  // logic to call only once 
}

Is it correct ? or any other simple way ?

~UK

+2  A: 

Sure:

BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam)
{
    /* do what you want with the first HWND */

    return FALSE; // stops enumeration.
}

See MSDN for full details, but the relevant line is this:

Return Value

BOOL

To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.

egrunin
+1,same way that I thought
TuxGeek
+2  A: 
BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam)
{
  // process first child window
  return FALSE;
}

Alternatively, HWND top_child = GetWindow(thisWindow, GW_CHILD);

Jerry Coffin
+1, I accept this answer . because this helps to get this one GetWindow(thisWindow,GW_HWNDFIRST) which I am using
TuxGeek
@Jerry: Edited to correct GWL_ to GW_
egrunin
@egrunin:Oops, thanks. Obviously I've used `GetWindowLong` a bit more often...
Jerry Coffin
+1  A: 

GetWindow(...,GW_CHILD) will give you the window at the top of the z-order which I assume is what you are after

Anders