lcOldPrinter = SET('Printer',2)
lcPrinter = GetPrinter()
IF lcOldPrinter <> lcPrinter
   DECLARE Integer SetDefaultPrinter
IN WINSPOOL.DRV String
  
IF SetDefaultPrinter(lcPrinter) = 0
      messagebox("Cannot change default
Windows Printer")
  
ENDIF
ENDIF 
DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
        INTEGER lnHWnd, ;
        STRING lcAction, ;   
        STRING lcFileName, ;
        STRING lcExeParams, ;
        STRING lcDefDir, ;
        INTEGER lnShowWindow
DECLARE Sleep ;
 
IN WIN32API ;
 
INTEGER nMillisecs
IF ShellExecute(0,"open", FULLPATH(This.cDefaultOutputFile),"","",1) > 32  
  
oShell = CreateObject("WScript.Shell")
  
IF VARTYPE(oShell) = "O"
      *wait for Acrobat reader
      lntimeout=60
      lnstarttime=SECONDS()
      DO WHILE not (oShell.AppActivate("Adobe
Reader") OR oShell.AppActivate("Adobe Acrobat")) AND ;
                      SECONDS()-lnstarttime<lntimeout
         sleep(2000)
      ENDDO
      IF oShell.AppActivate("Adobe
Reader") OR oShell.AppActivate("Adobe Acrobat")
         oShell.SendKeys("^p")   && print the file
         lnstarttime=SECONDS()
         DO WHILE NOT oShell.AppActivate("Print") AND SECONDS()-lnstarttime<lntimeout
            sleep(2000)
         ENDDO
         IF oShell.AppActivate("Print")
            oShell.SendKeys("{ENTER}")
         ENDIF 
         lnstarttime=SECONDS()
         * While printing, Acrobat reader cannot
be closed; so repeat attempts to close it.
         DO WHILE (oShell.AppActivate("Adobe
Reader") OR oShell.AppActivate("Adobe Acrobat")) AND ;
                           SECONDS()-lnstarttime<lntimeout
            oShell.SendKeys("^q")   && try to close Acrobat reader
            sleep(2000)
         enddo
      endif
      oShell=.null.
  
ENDIF 
ELSE
  
MESSAGEBOX("There's a problem with the Acrobat Reader.",64,'Reader problem')
ENDIF
IF lcOldPrinter <> lcPrinter
   * Reset back to original printer default
  
SetDefaultPrinter(lcOldPrinter)
ENDIF
No hay comentarios:
Publicar un comentario