#DEFINE GW_HWNDNEXT 2 DECLARE LONG GetParent In "user32" LONG HWND DECLARE LONG GetWindow In "user32" LONG HWND , LONG wCmd DECLARE LONG FindWindow In "user32" AS FindWindowA STRING lpClassName , STRING lpWindowName DECLARE LONG GetWindowText In "user32" AS GetWindowTextA LONG HWND, STRING @lplcing, LONG cch DECLARE LONG GetWindowThreadProcessId In "user32" LONG HWND , LONG @lpdwprocessid DECLARE INTEGER ShellExecute IN "shell32" INTEGER HWND, STRING lpOperation, STRING lpFile, STRING lpParameters, STRING lpDirectory, INTEGER nShowCmd LOCAL hInst && Instance handle from Shell function. LOCAL hWndApp && Window handle from GetWinHandle. LOCAL BUFFER && Holds caption of Window. LOCAL numChars && Count of bytes returned. *!* Shell to an application hInst = ShellExecute(0, "open", "calc.exe", "", "", 3) IF hInst > 32 *!* Begin search for handle hWndApp = GetWinHandle(hInst) IF hWndApp <> 0 *!* Init buffer BUFFER = SPACE$(128) *!* Get caption of window numChars = GetWindowTextA(hWndApp, @BUFFER, LEN(BUFFER)) *!* Display window's caption MESSAGEBOX("You shelled to the Application: " + LEFT(BUFFER, numChars)) ELSE MESSAGEBOX("Couldn't find the application") ENDIF ELSE MESSAGEBOX("There was a problem calling ShellExecute") ENDIF FUNCTION ProcIDFromWnd(HWND) LOCAL idProc *!* Get PID for this HWnd idProc = GetWindowThreadProcessId(HWND, 0) *!* Return PID RETURN (idProc) ENDFUNC FUNCTION GetWinHandle(hInstance) LOCAL tempHwnd *!* Grab the first window handle that Windows finds: tempHwnd = FindWindowA(NULL, NULL) *!* DO until you find a match or there are no more window handles: DO WHILE NOT tempHwnd = 0 *!* Check if no parent for this window IF GetParent(tempHwnd) = 0 *!* Check for PID match IF hInstance = ProcIDFromWnd(tempHwnd) *!* Exit search ENDDO EXIT ENDIF ENDIF *!* Get the next window handle tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT) ENDDO *!* Return found handle RETURN (tempHwnd) ENDFUNC #DEFINE GW_HWNDNEXT 2 DECLARE LONG GetParent In "user32" LONG HWND DECLARE LONG GetWindow In "user32" LONG HWND , LONG wCmd DECLARE LONG FindWindow In "user32" AS FindWindowA STRING lpClassName , STRING lpWindowName DECLARE LONG GetWindowText In "user32" AS GetWindowTextA LONG HWND, STRING @lplcing, LONG cch DECLARE LONG GetWindowThreadProcessId In "user32" LONG HWND , LONG @lpdwprocessid DECLARE INTEGER ShellExecute IN "shell32" INTEGER HWND, STRING lpOperation, STRING lpFile, STRING lpParameters, STRING lpDirectory, INTEGER nShowCmd LOCAL hInst && Instance handle from Shell function. LOCAL hWndApp && Window handle from GetWinHandle. LOCAL BUFFER && Holds caption of Window. LOCAL numChars && Count of bytes returned. *!* Shell to an application hInst = ShellExecute(0, "open", "calc.exe", "", "", 3) IF hInst > 32 *!* Begin search for handle hWndApp = GetWinHandle(hInst) IF hWndApp <> 0 *!* Init buffer BUFFER = SPACE$(128) *!* Get caption of window numChars = GetWindowTextA(hWndApp, @BUFFER, LEN(BUFFER)) *!* Display window's caption MESSAGEBOX("You shelled to the Application: " + LEFT(BUFFER, numChars)) ELSE MESSAGEBOX("Couldn't find the application") ENDIF ELSE MESSAGEBOX("There was a problem calling ShellExecute") ENDIF FUNCTION ProcIDFromWnd(HWND) LOCAL idProc *!* Get PID for this HWnd idProc = GetWindowThreadProcessId(HWND, 0) *!* Return PID RETURN (idProc) ENDFUNC FUNCTION GetWinHandle(hInstance) LOCAL tempHwnd *!* Grab the first window handle that Windows finds: tempHwnd = FindWindowA(NULL, NULL) *!* DO until you find a match or there are no more window handles: DO WHILE NOT tempHwnd = 0 *!* Check if no parent for this window IF GetParent(tempHwnd) = 0 *!* Check for PID match IF hInstance = ProcIDFromWnd(tempHwnd) *!* Exit search ENDDO EXIT ENDIF ENDIF *!* Get the next window handle tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT) ENDDO *!* Return found handle RETURN (tempHwnd) ENDFUNC>I converted the code to VFP and the return from GetWindowProcessID doesn't return the same thing that ShellExecute returns.