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

Just starting out? Need help? Post your questions and find answers here.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

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

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Did you create these child windows or do they exist in external apps :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

They exist in external apps.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 
Last edited by Sparkie on Thu Nov 15, 2007 3:52 am, edited 2 times in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Thanks Sparkie,

lets see now whats up with these child windows.
Post Reply