Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any way to speed this up?
Message
From
16/05/2006 19:24:37
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01122411
Message ID:
01122528
Views:
17
'Scan/endscan' might be faster than 'Do while' and 'm.' helps

>Hi everybody,
>
>I have the following program taken from UT to print PDF. It works, but it takes ~ 30 sec. or more to finish. May be you can find a way to improve it?
>
>Thanks in advance.
>
>
>*  Program...........: PRINTPDF
>*  Author............: John St. Andria thread #033100
>*  Project...........: Visual Collections
>*  Created...........: 04/14/2005  12:55:23
>*  Copyright.........: (c) Jzanus LTD, 2005
>*) Description.......: This function prints PDF passed as parameter and kills Adobe afterwards
>*  Calling Samples...:
>*  Parameter List....: tcPDF
>*  Major change list.:
>function PRINTPDF
>lparameters tcPDF
>
>wait window "System Printing PDF File......" nowait
>if vartype(m.tcPDF)<>"C" or adir(laFile, m.tcPDF) = 0
>	tcPDF = getfile("PDF","Select PDF file to print...")
>endif
>local llReturn
>llReturn = .f.
>if not empty(m.tcPDF)
>	local lcWindowTitle, lnWindowTitleLen, lnVFPhWnd, lnStart, lnReaderHwnd
>
>*== API Declarations
>	declare integer ShellExecute in "Shell32.dll" ;
>		integer hwnd, ;
>		string lpVerb, ;
>		string lpFile, ;
>		string lpParameters, ;
>		string lpDirectory, ;
>		long nShowCmd
>
>	declare SHORT   SetForegroundWindow in USER32.dll integer hwnd
>	declare integer SetActiveWindow in USER32 integer hwnd
>	declare integer FindWindow in Win32API string @lpClassName, string @lpWindowName
>	declare integer GetWindowText in WIN32API integer hwnd, string @lptstr, integer cbmax
>
>	lcWindowTitle = space(50)
>	lnWindowTitleLen = len(m.lcWindowTitle)
>
>*== Get HWND of current VFP session
>	if version(5) >= 800   && VFP8 and later carry hWnd property
>		lnVFPhWnd = _vfp.hwnd
>	else
>		declare integer GetForegroundWindow in win32API
>		lnVFPhWnd = GetForegroundWindow()
>	endif
>
>*== Print The PDF
>	= ShellExecute(0, "open", "acrord32.exe", " /p /h " + m.tcPDF, "", 0)
>
>*== Wait For Acrobat to Become Active
>	lnStart = datetime()
>	do while .t.
>		lnReaderHwnd = FindWindow(0, "Acrobat Reader")
>		if m.lnReaderHwnd = 0
>			lnReaderHwnd = FindWindow(0, "Adobe Reader")
>		endif
>		if m.lnReaderHwnd # 0 or datetime() - m.lnStart > 30   && 30 seconds max
>			exit
>		endif
>		MMSleep(100) && 1000 ms = 1 sec
>	enddo
>
>	if m.lnReaderHwnd = 0
>** Reader Did Not Start in 30 seconds.
>** Just Set Focus And Bail
>		SetForegroundWindow(lnVFPhWnd)
>		SetActiveWindow(lnVFPhWnd)
>		return
>	endif
>
>*== Printing has begun when PDF name appears in title of Reader window
>	do while .t.
>		GetWindowText(lnReaderHwnd, @lcWindowTitle, lnWindowTitleLen)
>		if upper(justfname(tcPDF))  $ upper(lcWindowTitle)
>			exit
>		endif
>	enddo
>
>*== Printing has finished when PDF name no longer in title
>	do while .t.
>		lcWindowTitle = space(50)
>		GetWindowText(lnReaderHwnd, @lcWindowTitle, lnWindowTitleLen)
>		if ! upper(justfname(tcPDF))  $ upper(lcWindowTitle)
>			exit
>		endif
>	enddo
>
>*== Kill Reader Process
>	if substr(os(1),9,1) >= "5"   && 4 = Win 98, 5= 2K & XP
>		local loWMI, loProcess
>		loWMI      = getobject("winmgmts://./root/cimv2")
>		loProcesses   = loWMI.ExecQuery("SELECT * FROM Win32_Process " + ;
>			"WHERE Name = 'AcroRd32.exe'")
>		for each loProcess in loProcesses
>			loProcess.terminate(0)
>		next
>
>		loProcesses   = loWMI.ExecQuery("SELECT * FROM Win32_Process " + ;
>			"WHERE Name = 'Acrobat.exe'")
>		for each loProcess in loProcesses
>			loProcess.terminate(0)
>		next
>	endif
>
>*== Set Focus to VFP
>	SetForegroundWindow(lnVFPhWnd)
>	SetActiveWindow(lnVFPhWnd)
>	llReturn = .t.
>endif
>return m.llReturn
>
I ain't skeert of nuttin eh?
Yikes! What was that?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform