#DEFINE normal_priority_class 32 #DEFINE idle_priority_class 64 #DEFINE high_priority_class 128 #DEFINE realtime_priority_class 1600 * Return code from WaitForSingleObject() if * it timed out. #DEFINE wait_timeout 0x00000102 * This controls how long, in milli secconds, WaitForSingleObject() * waits before it times out. Change this to suit your preferences. #DEFINE wait_interval 200 DECLARE INTEGER CreateProcess IN kernel32.DLL ; INTEGER lpApplicationName, ; STRING lpCommandLine, ; INTEGER lpProcessAttributes, ; INTEGER lpThreadAttributes, ; INTEGER bInheritHandles, ; INTEGER dwCreationFlags, ; INTEGER lpEnvironment, ; INTEGER lpCurrentDirectory, ; STRING @lpStartupInfo, ; STRING @lpProcessInformation DECLARE INTEGER WaitForSingleObject IN kernel32.DLL ; INTEGER hHandle, INTEGER dwMilliseconds DECLARE INTEGER CloseHandle IN kernel32.DLL ; INTEGER hObject DECLARE INTEGER GetLastError IN kernel32.DLL * STARTUPINFO is 68 bytes, of which we need to * initially populate the 'cb' or Count of Bytes member * with the overall length of the structure. * The remainder should be 0-filled START = long2str(68) + REPLICATE(CHR(0), 64) * PROCESS_INFORMATION structure is 4 longs, * or 4*4 bytes = 16 bytes, which we'll fill with nulls. process_info = REPLICATE(CHR(0), 16) * Start a copy of NOTEPAD (EXE name must be null-terminated) file2run = "C:\WINNT\NOTEPAD.EXE" + CHR(0) * Call CreateProcess, obtain a process handle. Treat the * application to run as the 'command line' argument, accept * all other defaults. Important to pass the start and * process_info by reference. retcode = createprocess(0, file2run, 0, 0, 1, ; normal_priority_class, 0, 0, @START, @process_info) * Unable to run, exit now. IF retcode = 0 =MESSAGEBOX("Error occurred. Error code: ", getlasterror()) RETURN ENDIF * Extract the process handle from the * PROCESS_INFORMATION structure. hprocess = str2long(SUBSTR(process_info, 1, 4)) DO WHILE .T. * Use timeout of TIMEOUT_INTERVAL msec so the display * will be updated. Otherwise, the VFP window never repaints until * the loop is exited. IF waitforsingleobject(hprocess, wait_interval) != wait_timeout EXIT ELSE DOEVENTS ENDIF ENDDO * Show a message box when we're done. =MESSAGEBOX ("Process completed") * Close the process handle afterwards. retcode = closehandle(hprocess) RETURN ******************** FUNCTION long2str ******************** * Passed : 32-bit non-negative numeric value (m.longval) * Returns : ASCII character representation of passed * value in low-high format (m.retstr) * Example : * m.long = 999999 * m.longstr = long2str(m.long) PARAMETERS m.longval PRIVATE i, m.retstr m.retstr = "" FOR i = 24 TO 0 STEP -8 m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr m.longval = MOD(m.longval, (2^i)) NEXT RETURN m.retstr ******************* FUNCTION str2long ******************* * Passed: 4-byte character string (m.longstr) * in low-high ASCII format * returns: long integer value * example: * m.longstr = "1111" * m.longval = str2long(m.longstr) PARAMETERS m.longstr PRIVATE i, m.retval m.retval = 0 FOR i = 0 TO 24 STEP 8 m.retval = m.retval + (ASC(m.longstr) * (2^i)) m.longstr = RIGHT(m.longstr, LEN(m.longstr) - 1) NEXT RETURN m.retval