*--Requires Acrobat Reader 4 or 5 *--Requires registry.vcx and path stored to xregclass *--Requires a .pdf form with the path included and stored in xform xregclass = "c:\programnotes\registry.vcx" xform = "C:\acordforms\61nc.pdf" IF !FILE(xform) .or. !FILE(xregclass) WAIT WINDOW "Cannot locate xregclass or xform!" NOWAIT RETURN ENDIF hdir = LEFT(xform,RAT('\',xform)-1) DO DECLexewait lcACORDdef = SYS(5)+SYS(2003) #DEFINE ERROR_SUCCESS 0 && OK oReg = NEWOBJECT("FileReg",xregclass) cAppKey = "" cAppName = "" m.cExtn = "PDF" nErrNum = oReg.GetAppPath(m.cExtn,@cAppKey,@cAppName) IF m.nErrNum # ERROR_SUCCESS && No associated pdf reader installed =MESSAGEBOX("Cannot locate Acrobat Reader. Please install and try again.",0+16+4096,"Acrobat Reader Missing.") RETURN ELSE && Adobe installed IF ATC(".EXE",m.cAppName) #0 m.cAppName= ALLTRIM(SUBSTR(m.cAppName,1,ATC(".EXE",m.cAppName)+3)) IF ASC(LEFT(cAppName,1))=34 &&check for long file name in quotes m.cAppName = SUBSTR(m.cAppName,2) ENDIF ENDIF SET DEFAULT TO LEFT(hdir,RAT("\",hdir)-1) lnpos=(RAT("\",m.cAppName)+1) && one position to the right of lcshort='' lcpath='' IF lnpos > 0 lcshort = UPPER(SUBSTR(m.cAppName,lnpos)) && grab from lnpos to end lcpath = UPPER(LEFT(m.cAppName,RAT("\",m.cAppName)-1)) && strip off the extension ENDIF IF EMPTY(m.cAppName) =MESSAGEBOX("Cannot locate Acrobat Reader. Please install and try again.",0+16+4096,"Acrobat Reader Missing.") ELSE IF !EMPTY(lcshort) .AND. !EMPTY(lcpath) lcpath = "'"+lcpath+"'" SET DEFAULT TO &lcpath llok = ExeWait(lcshort,xform,lcpath) ELSE llok = ExeWait( m.cAppName, xform, hdir) ENDIF IF !llok =MESSAGEBOX("Unable to open pdf reader.",0+16+4096,"ERROR") ELSE WAIT WINDOW "Successfully Finished" NOWAIT ENDIF ENDIF ENDIF ? lcAcorddef set STEP on SET DEFAULT TO &lcACORDdef PRIVATE idll, lcdll PRIVATE ARRAY dllarray(1) =ADLLS(dllarray) FOR idll = 1 TO ALEN(dllarray,1) lcdll = dllarray(idll,1) lccommand = "Clear DLLS "+"'"+lcdll+"'" &lccommand ENDFOR =ADLLS(dllarray) RETURN .T. *---------------------------------------------------------------------- *--PROCEDURE ExeWait *---------------------------------------------------------------------- *--Uses GetExitcodeProcess instead of waitforsingleobject *---------------------------------------------------------------------- FUNCTION ExeWait(lcApp, lcCmdLine, lcdir) PRIVATE llsetback, file_han, lnstart, lngone, lnElapsed, lnBegin, lcOldSetHours, exitcode, lnlast lnlast = 0 IF _VFP.AUTOYIELD = .F. llsetback = .T. ELSE llsetback = .F. ENDIF _VFP.AUTOYIELD = .T. #DEFINE INFINITE 0xFFFFFFFF LOCAL lcStartupInfo, lcProcInfo, hProcess, ; lnPrio, lnIBelieve1 lnIBelieve1 = 1 && Don't remember what that was lnPrio = 32 && Priority of Process=Normal lcStartupInfo = CHR(68) + REPLI(CHR(0), 67) lcProcInfo = REPLI(CHR(0), 16) IF CreateProcess(0, m.lcApp+" "+m.lcCmdLine+CHR(0), 0,0,; m.lnIBelieve1, m.lnPrio,; 0, 0, @lcStartupInfo, @lcProcInfo) <> 0 * process and thread handles returned in ProcInfo structure hProcess = buf2dword(SUBSTR(lcProcInfo, 1,4)) hThread = buf2dword(SUBSTR(lcProcInfo, 5,4)) * waiting until the termination of the program DOEVENTS lcOldSetHours = SET("HOURS") SET HOURS TO 24 lnBegin = DATETIME() DO WHILE .T. exitcode = 0 && initialize return value to 0 = GetExitCodeProcess(hProcess, @exitcode) && try to obtain process exit code IF exitcode # 259 && not still busy EXIT && fall out of loop ENDIF = Sleep (100) && wait .1 seconds lnElapsed = DATETIME() - lnBegin *--Just in Case - (a double-check) IF lnElapsed > 60 .AND. (lnElapsed > (lnlast + 10)) && give app 60 seconds at least to startup and run lnlast = lnElapsed && 10 seconds between each attempt file_han = FOPEN(pdffile,12) IF file_han > 0 && can open the file read and write unbuffered =FCLOSE(file_han) EXIT ENDIF ENDIF ENDDO SET HOURS TO &lcOldSetHours = CloseHandle(hThread) = CloseHandle(hProcess) ELSE IF llsetback _VFP.AUTOYIELD = .F. ENDIF RETURN .F. ENDIF IF llsetback _VFP.AUTOYIELD = .F. ENDIF RETURN .T. *---------------------------------------------------------------------- PROCEDURE DECLexewait && load required dlls for exewait function =ADLLS(dllarray) IF TYPE('ALEN(dllarray,1)')="U" DIMENSION dllarray(1) dllarray(1)="" ENDIF IF ASCAN(dllarray,'CREATEPROCESS') = 0 DECLARE INTEGER CreateProcess IN kernel32; INTEGER lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,; INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,; INTEGER lpEnvir, INTEGER lpCurDir, ; STRING @lpStInfo, STRING @lpProcInfo ENDIF IF ASCAN(dllarray,'GETLASTERROR') = 0 DECLARE INTEGER GetLastError IN kernel32 ENDIF IF ASCAN(dllarray,"CLOSEHANDLE") = 0 DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject ENDIF IF ASCAN(dllarray,"GETEXITCODEPROCESS") = 0 DECLARE INTEGER GetExitCodeProcess IN WIN32API INTEGER hProcess, INTEGER @lpExitCode ENDIF IF ASCAN(dllarray,"SLEEP") = 0 DECLARE Sleep IN kernel32 INTEGER dwMilliseconds ENDIF RETURN FUNCTION buf2dword(lcBuffer) RETURN ASC(SUBSTR(lcBuffer, 1,1)) + ; ASC(SUBSTR(lcBuffer, 2,1)) * 256 +; ASC(SUBSTR(lcBuffer, 3,1)) * 65536 +; ASC(SUBSTR(lcBuffer, 4,1)) * 16777216 RETURN