Finding MDI Child windows

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
delta1
Junior Coder
Posts: 26
Joined: Wed Dec 16, 2009 11:23 pm

Finding MDI Child windows

Post by delta1 » Fri Jun 18, 2010 3:47 pm

I want to make a toolbar to activate my current windows in my CAD application rather than going to the window menu and choosing them from a list. My first problem is I do not know how to get a list of child windows present. ?

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jun 21, 2010 5:45 pm

Have you looked in Macro Scheduler under the "Tools" menu for "View System Windows"

Also I have a utility that will display information about a currently selected window. An executable for the utility is HERE. The Macro Scheduler code is HERE

delta1
Junior Coder
Posts: 26
Joined: Wed Dec 16, 2009 11:23 pm

Post by delta1 » Mon Jun 21, 2010 7:21 pm

Thanks. I can see child windows with "view system windows" but I need to load them into variables at run time. GetWindowList almost works but it only provides the top level windows.

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jun 21, 2010 9:55 pm

I wrote this back while v12 was in beta as a proof of concept. Basically it uses Window's "GetWindow" API function to move through the child windows and build a list. This sample is built to look specifically at the windows XP "Display Properties" window. If you open "Display Properties" then open "View System Windows" and expand the child window list to see the window handles and names. You should be able to then run this script and see that list show up one child window at a time in the message box or listed in the file %temp_dir%childwindowlist.txt.

Hope this is helpful.

Code: Select all

/*
GetWindow params
#define GW_HWNDFIRST        0
#define GW_HWNDLAST         1
#define GW_HWNDNEXT         2
#define GW_HWNDPREV         3
#define GW_OWNER            4
#define GW_CHILD            5
*/

//Run>desk.cpl

Let>kk=1
LibFunc>user32,GetDesktopWindow,hwnd
LibFunc>user32,GetWindow,GWres,hwnd,5
GetWindowNames>GWres,title,class
Writeln>%temp_dir%childwindowlist.txt,wres,Handle=%GWres%%TAB%Name=%title%%TAB%Class=%class%
Let>Window_%kk%=%GWres%

Repeat>GWres
  Add>kk,1
  LibFunc>user32,GetWindow,GWres,%GWres%,2
  Let>Window_%kk%=%GWres%
  GetWindowNames>GWres,title,class
  Let>WinName=Window_Name_%kk%
  MDL>Handle=%GWres%%CRLF%Name=%title%%CRLF%Class=%class%
  Writeln>%temp_dir%childwindowlist.txt,wres,Handle=%GWres%%TAB%Name=%title%%TAB%Class=%class%
Until>GWres=0


Let>kkk=1
Let>GWress=Window_1
LibFunc>user32,GetWindow,GWress,GWress,5
GetWindowNames>GWress,title,class
Writeln>%temp_dir%childwindowlist.txt,wres,Handle=%GWress%%TAB%Name=%title%%TAB%Class=%class%
Let>Window_%kkk%=%GWress%

Repeat>GWress
  Add>kkk,1
  LibFunc>user32,GetWindow,GWress,%GWress%,2
  Let>Window_%kkk%=%GWress%
  GetWindowNames>GWress,title,class
  Let>WinName=Window_Name_%kkk%
  MDL>Handle=%GWress%%CRLF%Name=%title%%CRLF%Class=%class%
  Writeln>%temp_dir%childwindowlist.txt,wres,Handle=%GWress%%TAB%Name=%title%%TAB%Class=%class%
Until>GWress=0

delta1
Junior Coder
Posts: 26
Joined: Wed Dec 16, 2009 11:23 pm

Post by delta1 » Tue Jun 22, 2010 12:41 am

Thanks. I will check it out.
Rob

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts