* GetProcessChildWindows sample code; * Richard A. DeVenezia; * http://www.devenezia.com; * rad4sas.dll must be in system PATH; filename SASCBTBL catalog 'WORK.WINAPI.WINAPI.SOURCE'; data _null_; file SASCBTBL; input ; put _infile_; cards4; routine GetProcessChildWindows module = rad4sas minarg = 2 maxarg = 2 returns = long ; * stackpop = called ; arg 1 input num byvalue format=pib4. ; arg 2 input num byvalue format=pib4. ; routine GetWindowTextA module = user32 minarg = 3 maxarg = 3 stackpop = called returns = long ; arg 1 num input byvalue format=pib4.; arg 2 char update byaddr format=$CSTR200. ; arg 3 num input byvalue format=pib4.; routine GetMenu module = user32 minarg = 1 maxarg = 1 stackpop = called returns = long ; arg 1 num input byvalue format=pib4.; * HWND hWnd; routine GetSubMenu module = user32 minarg = 2 maxarg = 2 stackpop = called returns = long ; arg 1 num input byvalue format=pib4.; * HMENU hMenu; arg 2 num input byvalue format=pib4.; * int nPos; routine GetMenuItemInfoA module = user32 minarg = 15 maxarg = 15 stackpop = called returns = long ; arg 1 num input fdstart byvalue format=pib4.; * HMENU hMenu; arg 2 num input fdstart byvalue format=pib4.; * UINT uItem; arg 3 num input fdstart byvalue format=pib4.; * BOOL fByPosition; arg 4 num input fdstart format=pib4.; * cbSize LPMENUITEMINFO lpmii; arg 5 num input format=pib4.; * fMask; arg 6 num input format=pib4.; * fType; arg 7 num output format=pib4.; * fState; arg 8 num output format=pib4.; * wID; arg 9 num output format=pib4.; * hSubMenu; arg 10 num output format=pib4.; * hbmpChecked; arg 11 num output format=pib4.; * hbmpUnchecked; arg 12 num output format=pib4.; * dwItemData; arg 13 num input format=pib4.; * dwTypeData (use addr()); arg 14 num update format=pib4.; * cch; arg 15 num output format=pib4.; * hbmpItem; ;;;; data SASwindows; array handle [1:100, 1:2] $4 _temporary_; handle[1,1] = "1,1"||'00'x; handle[1,2] = "1,2"||'00'x; handle[2,1] = "2,1"||'00'x; handle[2,2] = "2,2"||'00'x; rccw = modulen ('GetProcessChildWindows', addr(handle[1,1]), dim1(handle)); drop rccw; hWndCount = band (rccw, 0FF00x) / 0100x; enumCount = band (rccw, 000FFx); put hWndCount= enumCount=; drop hWndCount enumCount; format parentHWND childHWND HEX8.; * 8 nibbles needed to display 32 bits ; length parentTitle childTitle $200; do i = 1 to min (enumCount, dim1(handle)); parentHWND = peek (addr (handle[i,1])); childHWND = peek (addr (handle[i,2])); * the important thing here is that the Win32 HWND handles are * now available for use in the full range of Win32 User32.dll * procedures; rcp = ModuleN ( '*e', 'GetWindowTextA', parentHWND, parentTitle, 200); rcc = 0; if childHWND ne 0 then rcc = ModuleN ( '*e', 'GetWindowTextA', childHWND, childTitle, 200); else childTitle = 'n/a'; put i= parentHWND= parentTitle= childHWND= childTitle= cmenuH= pmenuH=; cmenuH = ModuleN ( 'GetMenu', childHWND ); pmenuH = ModuleN ( 'GetMenu', parentHWND ); if parentHWND ne lag(parentHWND) then do; put +1 '-- getting parentHWND menu --'; do npos = 0 by 1 until (smenuH = 0); smenuH = ModuleN ( 'GetSubMenu', pmenuH, npos); if smenuH then do; length menutext $200; MIIM_STRING = 00000040x; MFT_STRING = 0; null = 0; * get # of chars in menu text; nchars=200; menutext = ''; rc = ModuleN ( 'GetMenuItemInfoA', pmenuH, npos, 1 , 48 , MIIM_STRING , MFT_STRING , 0 /* fstate */ , 0 /* wid */ , 0 /* hsubmenu */ , 0 /* hbmpChecked */ , 0 /* hbmpUnchecked */ , 0 /* dwItemData */ , addr(menutext) /* dwTypeData */ , nchars , null /* hbmpitem */ ); if rc and nchars>0 then menutext = substr(menutext,1,nchars); if rc & nchars > 0 then put +1 npos= menuText= ; do npos2 = 0 by 1 until (rc = 0); nchars=200; menutext = ''; rc = ModuleN ( 'GetMenuItemInfoA', smenuH, npos2, 1 , 48 , MIIM_STRING , MFT_STRING , 0 /* fstate */ , 0 /* wid */ , 0 /* hsubmenu */ , 0 /* hbmpChecked */ , 0 /* hbmpUnchecked */ , 0 /* dwItemData */ , addr(menutext) /* dwTypeData */ , nchars , null /* hbmpitem */ ); if rc and nchars>0 then menutext = substr(menutext,1,nchars); if rc & nchars > 0 then put +2 npos2= menuText= nchars=; end; end; end; end; if cmenuH then do; put +1 '-- getting childHWND menu --'; do npos = 0 by 1 until (smenuH = 0); smenuH = ModuleN ( 'GetSubMenu', cmenuH, npos); if smenuH then do; length menutext $200; MIIM_STRING = 00000040x; MFT_STRING = 0; null = 0; * get # of chars in menu text; nchars=200; menutext = ''; rc = ModuleN ( 'GetMenuItemInfoA', pmenuH, npos, 1 , 48 , MIIM_STRING , MFT_STRING , 0 /* fstate */ , 0 /* wid */ , 0 /* hsubmenu */ , 0 /* hbmpChecked */ , 0 /* hbmpUnchecked */ , 0 /* dwItemData */ , addr(menutext) /* dwTypeData */ , nchars , null /* hbmpitem */ ); if rc and nchars>0 then menutext = substr(menutext,1,nchars); if rc & nchars > 0 then put +1 npos= menuText= ; do npos2 = 0 by 1 until (rc = 0); nchars=200; menutext = ''; rc = ModuleN ( 'GetMenuItemInfoA', smenuH, npos2, 1 , 48 , MIIM_STRING , MFT_STRING , 0 /* fstate */ , 0 /* wid */ , 0 /* hsubmenu */ , 0 /* hbmpChecked */ , 0 /* hbmpUnchecked */ , 0 /* dwItemData */ , addr(menutext) /* dwTypeData */ , nchars , null /* hbmpitem */ ); if rc and nchars>0 then menutext = substr(menutext,1,nchars); if rc & nchars > 0 then put +2 npos2= menuText= nchars=; end; end; end; end; output; end; stop; drop i rcp rcc; format cmenuH pmenuH smenuH hex8.; run;