Page 1 of 1

Child Windows - names, handles and ID's - help please

Posted: Mon Jan 30, 2006 1:37 am
by SFSxOI
How do you get (return) the names, handles, and windowID of child windows in applications?

Not eveything running. I can do it for the main windows of applications, having problems with child windows.

Thank you

Posted: Mon Jan 30, 2006 4:34 am
by Sparkie
Did you create these child windows or do they exist in external apps :?:

Posted: Mon Jan 30, 2006 1:28 pm
by SFSxOI
They exist in external apps.

Posted: Mon Jan 30, 2006 4:55 pm
by Sparkie

Posted: Mon Jan 30, 2006 6:00 pm
by SFSxOI
Sparkie, I already looked at that API. It needs

HWND hwndParent < i have this OK
HWND hwndChildAfter <I dont know this one - can be null
LPCTSTR lpszClass < dunno
LPCTSTR lpszWindow < dunno - can be null?

OK, so I did:

FindWindowEx_(hwnd of the partent which i have, #Null and should do all child, hmmm - dont know the class, #Null)

gave it a try, always returns a 0.

Posted: Mon Jan 30, 2006 6:08 pm
by Sparkie
If hwndChildAfter and lpszClass and lpszWindow are ALL #Null, then there is nothing to find.

Maybe EnumChildWindows_() will be a better option.
http://msdn.microsoft.com/library/defau ... indows.asp

Posted: Mon Jan 30, 2006 9:23 pm
by Sparkie
Here's a little example of EnumWindows() and EnumChildWindows() that I slapped together that might help. :)

Code: Select all

; ************************************************ 
; Code:   EnumWindows / EnumChildWindows 
; Author: Sparkie 
; Date:   January 30, 2006 
; OS:     Windows only 
; PB:     4.xx
; Notes:  Upadted to PB 4 on November 14, 2007
; ************************************************ 

Procedure.l enumChildren(hwnd.l, lParam.l) 
  If hwnd  
    parentText.s = Space(256)
    childText.s = Space(256)
    classText.s = Space(256)
    childID = GetDlgCtrlID_(hwnd) 
    SendMessage_(hwnd, #WM_GETTEXT, 256, @childText)
    GetClassName_(hwnd, @classText, 256) 
    GetWindowRect_(hwnd, @winRc.RECT)
    winW.s = Str(winRc\right - winRc\left)
    winH.s = Str(winRc\bottom - winRc\top)
    AddGadgetItem(1, -1, Str(hwnd) + Chr(10) + Str(childID) + Chr(10) + childText + Chr(10) + classText + Chr(10) + winW + Chr(10) + winH) 
    ProcedureReturn 1 
  Else 
    ProcedureReturn 0 
  EndIf 
EndProcedure 

Procedure.l enumWins(hwnd.l, lParam.l) 
  If hwnd 
    ;... Only looking for visible windows with this one 
    If IsWindowVisible_(hwnd) 
      pText.s = Space(256)
      SendMessage_(hwnd, #WM_GETTEXT, 256, @pText) 
      AddGadgetItem(2, 0, Str(hwnd) + " " + pText)
    EndIf 
    ProcedureReturn 1 
  Else 
    ProcedureReturn 0 
  EndIf 
EndProcedure 

If OpenWindow(0, 0, 0, 775, 500, "EnumWindows/ChildWindows", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0)) 
  TextGadget(0, 10, 15, 100, 22, "Select Parent -->") 
  ComboBoxGadget(2, 120, 10, 645, 200) 
  ListIconGadget(1, 10, 40, 755, 350, "Child Handle", 100, #PB_ListIcon_FullRowSelect) 
  AddGadgetColumn(1, 1, "ID", 50) 
  AddGadgetColumn(1, 2, "Text", 300) 
  AddGadgetColumn(1, 3, "Class", 200) 
  AddGadgetColumn(1, 4, "Width", 50)
  AddGadgetColumn(1, 5, "Height", 50)
  EnumWindows_(@enumWins(), 0) 
  SetGadgetState(2, 0) 
  hParent = Val(StringField(GetGadgetText(2), 1, " ")) 
  EnumChildWindows_(hParent, @enumChildren(), 0) 
  Repeat 
    event = WaitWindowEvent() 
    If EventType() = 1 And EventGadget() = 2 
      ClearGadgetItemList(1) 
      hParent = Val(StringField(GetGadgetText(2), 1, " ")) 
      EnumChildWindows_(hParent, @enumChildren(), 0) 
    EndIf 
  Until event = #PB_Event_CloseWindow 
EndIf 
End 

Posted: Mon Jan 30, 2006 10:14 pm
by SFSxOI
Thanks Sparkie,

lets see now whats up with these child windows.