Chris -
I have created a sample program that I think will give you some ideas on how to handle file viewing in an Xbase++ application.
Here is FileViewer.Prg
The FileViewer.Zip also includes a file named Viewer.aapp
This should be copied to your
C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroApp\ENU folder to overwrite the existing file.
It will suppress the toolbar that is in the free version of Acrobat Reader DC.
After working closely with 2 customers who use this file viewing system in their documents systems, we have all agreed on the best way to handle viewing of documents inside an Xbase++ application.
Here is the part of the code that does the viewing of the document.
If the document type is an image, then it is put into the viewer via an html file that makes sure the image is sized for viewing.
If the document type is not supported by XbpHtmlViewer, then a message is put in the viewer telling the user to double-click the document for viewing with the registered program for that extension type. A double-click will spawn it.
If the document type is not registered, then a message is put into the viewer that it cannot be viewed.
Code: Select all
STATIC FUNCTION ViewDocument( oViewer, cDoc, lItemSelected, oBrowse )
LOCAL cHtml, cDocType := '', aRef, aData, lIsValidType, aBranch
cDocType := Upper(cDoc)
cDocType := Substr(cDocType,_AtLast(cDocType,'.'))
aBranch := DC_RegQueryBranch(HKEY_CURRENT_USER, ;
'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\' + ;
Lower(cDocType) + '\UserChoice')
IF Empty(aBranch)
aBranch := DC_RegQueryBranch(HKEY_CURRENT_USER, ;
'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\' + ;
Lower(cDocType) + '\OpenWithProgids')
ENDIF
lIsValidType := !Empty(aBranch)
IF cDocType $ {'.JPG','.PNG', '.GIF', '.TIFF', '.TIF'}
// Send image to viewer in a <IMG> tag
IF !lItemSelected
cHtml := '<img src="' + cDoc + '" width=' + Alltrim(Str(oViewer:currentSize()[1]-20)) + '>'
MemoWrit('Viewer.Htm',cHtml)
cDoc := DC_CurPath()+'\' + 'viewer.htm'
Sleep(10)
oViewer:Navigate(cDoc)
ENDIF
ELSEIF cDocType $ {'.TXT','.PDF','.HTML','.XML','.HTM','.ZIP','.ICO','.BMP','.RTF'}
// Send it to viewer
// To suppress Acrobat DC Toolbar, copy viewer.aapp to the following folder:
// Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroApp\ENU
oViewer:Navigate(cDoc)
ELSE
// Spawn it and show a message in the viewer
IF cDocType $ {'.XLS','.XLSX','.CSV'}
cDocType := 'Microsoft Excel'
ELSEIF cDocType $ {'.DOC','.DOCX'}
cDocType := 'Microsoft Word'
ELSEIF cDocType $ {'.MOV','.AVI','.MP4'}
cDocType := 'Video'
ENDIF
IF lIsValidType
cHtml := '<H2>Your ' + cDocType + ' document will be displayed in a new window.<br><br>'
cHtml += 'Press the ENTER key or Double click the document name to view the document'
ELSE
cHtml := '<H2>Your document has no registered program that is associated with '
cHtml += 'this file type: ' + cDocType
ENDIF
IF !lItemSelected
MemoWrit('Viewer.Htm',cHtml)
cDoc := DC_CurPath()+'\' + 'viewer.htm'
Sleep(10)
oViewer:Navigate(cDoc)
ENDIF
ENDIF
IF lItemSelected
DC_SpawnUrl(cDoc)
ENDIF
SetAppFocus(oBrowse)
RETURN nil
The sample program suppresses showing any kind of document that should not be spawned, such as .EXE, .DLL, etc.