>#include "vfp2c.h" > >DIMENSION hWnds[1, 2] >AWindowsEx('hWnds', 'WO', AWINDOWS_TOPLEVEL) >>
* * * Original source: * "List child windows for the Windows desktop" from https://github.com/VFPX/Win32API/blob/master/samples/sample_027.md * * Modified by: Marco Plaza, github.com/nftools : * added GetWindowThreadProcessId() to get the PID from hWnd * saves to cursor all running applications with their hwnd & corresponding PID's. * #Define GW_HWNDLAST 1 #Define GW_HWNDNEXT 2 #Define GW_CHILD 5 Do Declare Create Cursor csResult (HWnd N(12), pid i,isvisible N(1),; leftpos i, toppos i, rightpos i, botpos i, wincap C(64), classname C(64)) Local hDesktop, hFirstChild, hLastChild, rc, cWinCap, cWinClass,; nVisible, nLeft, nTop, nRight, nBottom hDesktop = GetDesktopWindow() hFirstChild = GetWindow(m.hDesktop, GW_CHILD) hLastChild = GetWindow(m.hFirstChild, GW_HWNDLAST) hCurrent = m.hFirstChild Do While .T. cWinCap = GetWinText(m.hCurrent) cWinClass= GetClsName(m.hCurrent) nVisible = IsWindowVisible(m.hCurrent) rc = Repli(Chr(0),16) = GetWindowRect(m.hCurrent, @rc) nLeft = buf2dword(Substr(m.rc, 1,4)) nTop = buf2dword(Substr(m.rc, 5,4)) nRight = buf2dword(Substr(m.rc, 9,4)) nBottom = buf2dword(Substr(m.rc, 13,4)) pidx = 0 GetWindowThreadProcessId(m.hCurrent,@pidx) Insert Into csResult Values (m.hCurrent, m.pidx, m.nVisible,m.nLeft, m.nTop, m.nRight, m.nBottom, m.cWinCap, m.cWinClass) If m.hCurrent = m.hLastChild Exit Endif hCurrent = GetWindow(m.hCurrent, GW_HWNDNEXT) Enddo Go Top Browse Normal Nowait *------------------------------------------ Function GetClsName(hWindow) *------------------------------------------ Local nBufsize, cBuffer cBuffer = Repli(Chr(0), 250) nBufsize = GetClassName(hWindow, @cBuffer, Len(cBuffer)) Return Substr(cBuffer, 1, nBufsize) *---------------------------------------- Function GetWinText(hWindow) *---------------------------------------- Local cBuffer, nResult cBuffer = Space(250) nResult = GetWindowText(hWindow, @cBuffer, Len(cBuffer)) Return Substr(cBuffer, 1, nResult) *---------------------------------------------------- Function buf2dword(lcBuffer) *---------------------------------------------------- Return Asc(Substr(lcBuffer, 1,1)) + ; BitLShift(Asc(Substr(lcBuffer, 2,1)), 8) +; BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +; BitLShift(Asc(Substr(lcBuffer, 4,1)), 24) *---------------------------------------------------- Procedure Declare *---------------------------------------------------- Declare Integer GetDesktopWindow In user32 Declare Integer GetWindow In user32 Integer HWnd, Integer wFlag Declare Integer GetWindowRect In user32 Integer HWnd, String @lpRect Declare Integer IsWindowVisible In user32 Integer HWnd Declare Integer GetWindowText In user32; INTEGER HWnd, String @lpString, Integer cch Declare Integer GetClassName In user32; INTEGER HWnd, String lpClassName, Integer nMaxCount Declare Integer GetWindowThreadProcessId In user32 Integer HWnd, Integer @pid