Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to know if IE has been installed?

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi,

I found a nice piece of code somewhere on the display PDF's in VFP-form. The trick is that PDF is displayed in IE-explorer (IE can display PDF!).

Q: To be sure this solutions works properly in my app:
How can I check if IE is installed?

-Bart
 
Another way to show PDFs is to call whatever application is registered for PDF files with Shellexecute().

Code:
DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
INTEGER nWinHandle, STRING cOperation, ;
STRING cFileName, STRING cParameters, ;
STRING cDirectory, INTEGER nShowWindow

*-- set Parameters
Local lcOperation, lcFileName, lcParameter, lcWorkDir

lcOperation = "open"
lcFileName = "C:\Path\to\Some.pdf"
lcParameter = ""
lcWorkDir = ""

*-- Execute PDF Viewer
ShellExecute(0, lcOperation, lcFilename, lcParameter, lcWorkdir, 1)

Now the user can decide what program he wants as a PDF viewer. You also can change the Action from "open" to "print", to print PDF files.

Bye, Olaf.
 
Hi to all,

Chris, That's indeed most simply way. Stupid I didnot ythink of myself!

Olaf, Does this piece of code work for you? I put valid pdfname in code but as far as I can see nothing happens.

Mike, knowing you can read some Dutch:
This tells Windows 7 will be delivered without installed explorer

-Bart
 
Bart and Chris,

Interesting. So, the EC's action against Microsoft has paid off. Probably a good thing politically, but presumably we're going to have to distribute the IE components with our apps from now on.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Bart,

Back to the technical issue ....

I don't know how you are using IE to display your PDFs. If you are instantiating a web browser control and using its Navigate2 to open the PDF, be aware that this will require the user to have specified the "Display PDF in Browser" option in the Adobe reader. If they haven't, the reader will open in its own window, which might not be what you want.

Off-hand, I don't know of any workaround for that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike,

This is the code I found at:
Most of my needs are covered with this nice piece of code.
I tailored it a bit so that I can call the form with a single parameter being the PDF path/filename.
What I now still looking for is how to get on the toolbar the rotate-buttons.

-Bart

Code:
PUBLIC oform1
 
oForm1=NEWOBJECT("form1")
oForm1.Show()
RETURN
 
DEFINE CLASS form1 AS form
 
	Autocenter = .T.
	Height = 520
	Width = 741
	Caption = "Form1"
	Name = "Form1"
 
	&& PDF file name
	cPdfFileName = "=SPACE(0)"
	&& How long to wait for PDF to load
	nPdfLoadTimeout = 30 			
 
	ADD OBJECT txtpdfname AS textbox WITH ;
		Top = 471, Left = 108, Height = 23, Width = 492, ;
		ReadOnly = .T., Name = "txtPdfName"
 
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 469, Left = 623, Height = 27, Width = 84, ;
		Caption = "View PDF", Name = "Command1"
 
	ADD OBJECT owb AS olecontrol WITH ;
		Top = 24, Left = 12, Height = 433, Width = 709, ;
		OleClass = "Shell.Explorer.2", Name = "oWB"
 
	ADD OBJECT label1 AS label WITH ;
		Height = 17, Left = 36, Top = 474, Width = 63, ;
		Caption = "PDF Name", Name = "Label1"
 
	PROCEDURE Refresh
		&& Required in VFP8 and earlier to prevent an error
		NODEFAULT
	ENDPROC
	
	
	PROCEDURE ShowPdf
		LOCAL lnSeconds
		&& Clear Web browser control by loading blank page
		Thisform.oWB.OBJECT.Navigate2("About:Blank")
		&& Wait for load to complete
		lnSeconds = SECONDS()
		DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ;
				AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout
			DOEVENTS
		ENDDO
 
		&& Load PDF
		WAIT WINDOW NOWAIT "Loading PDF ..."
		Thisform.oWB.OBJECT.Navigate2(Thisform.cPdfFileName)
		&& Wait for PDF to load
		lnSeconds = SECONDS()
		DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ;
				AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout
			DOEVENTS
		ENDDO
		WAIT CLEAR
 
		&& PDF display can be adjusted as shown in AdjustPdfView method 
 		&&   Uncomment next line if you want to do that and add AdjustPdfView method to the form/class
		=This.AdjustPdfView()
 
	ENDPROC
 
	PROCEDURE command1.Click
		&& Get PDF file name
		Thisform.cPdfFileName = GETFILE("pdf")
		&& Display the name in the textbox
		Thisform.txtPdfName.Value = Thisform.cPdfFileName
		IF NOT EMPTY(Thisform.cPdfFileName)
			&& Display PDF
			Thisform.ShowPdf()
		ENDIF
	ENDPROC
 




PROCEDURE AdjustPdfView
		&& PDF control PEMs can only be accessed after it's loaded
		&&  TRY...ENDTRY will prevent crash in case when it's not loaded
		TRY
			loDoc = Thisform.oWB.oBJECT.Document
			WITH loDoc 
				&& PageMode: 
				&&	none — does not display bookmarks or thumbnails (default)
				&& 	bookmarks — displays the document and bookmarks
				&& 	thumbs — displays the document and thumbnails
				.setPageMode("none")
 
				&& LayoutMode:
				&&	DontCare — use the current user preference
				&&	SinglePage — use single page mode (as it would have appeared in pre-Acrobat 3.0 viewers)
				&&	OneColumn — use one-column continuous mode
				&&	TwoColumnLeft — use two-column continuous mode with the first page on the left
				&&	TwoColumnRight — use two-column continuous mode with the first page on the right
				.setLayoutMode("OneColumn")
 
				&& ViewMode:
				&&	Fit — Fits the entire page within the window both vertically and horizontally.
				&&	FitH — Fits the entire width of the page within the window.
				.setView("FitH")
 
				&& Zoom %, overrides ViewMode and vise verse. 
				.setZoom(50)
 
				&& Toolbar On/Off
				.setShowToolbar(.F.)
				&& Scrollbars On/Off
				.setShowScrollbars(.T.)
			ENDWITH
		CATCH TO oErr	
		FINALLY 	
			loDoc = null
		ENDTRY	
	ENDPROC
	
	ENDDEFINE
 
Bart,

yes, the ShellExecute Code works for me. I have installed a PDF reader (Foxit Reader, but it also works with Adobe Reader). If it doesn't work, make double sure the file name is an absolute path, as the PDF reader called has absolutely no idea of Foxpros current directory.

And if that doesn't work, then check, if the PDF file extension is registerd with any program at all.

Bye, Olaf.
 
You can use FindExecutable API to search which application is associated with the extension.
 
All too difficult guys,

just use the IF FILE() function, that will do.
Not installed item then Run \N what ever to install
Lol

I note that in VFP and VBA people tend to write up enceclopedias of unnecesarry code. Shows they never had to do something on a Commodore C-64 with 16K there.

Be sure to include some fool proof re-surrection code in your appz to check if al db's are there and not corrupted.
If missing or corupted let them 7-unzip automatic i.e.

Like hey I love my coffee and donut enjoying the sun.

Greetz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top