Page 1 of 1
Test for a .Pdf reader
Posted:
Wed Nov 09, 2011 10:11 pm
by Rick Lipkin
To All
In doing some QA testing with one of my applications .. I am using SHELLEXECUTE to open a .PDF help file .. One person in my test group ( from the usual suspects ) did not have ANY .pdf reader so when you clicked on the Help line .. nothing happened.
Is there a way to capture whether there is a 'default' .Pdf reader installed on a computer ?
Thanks
Rick Lipkin
- Code: Select all Expand view
//-------------------------
Static Func _Webhelp( cOLDDEFA, dEXE )
LOCAL oDLG,oBRU, oSAY, oSAY1, Saying, oHand, x
DEFINE BRUSH oBru FILENAME ( cOLDDEFA+"\CCI.BMP" )
DEFINE CURSOR oHAND HAND
DEFINE DIALOG oDLG ;
TITLE "About this Program" ;
SIZE 555, 290 BRUSH oBRU TRANSPARENT
@ 7,10 SAY oSay PROMPT "Click here for the HELP Manual" ;
PIXEL of oDLG COLOR "N+/W"
oDlg:aControls[ 1 ]:lTransparent = .t.
@ 130,10 SAY oSay1 PROMPT "Revision Date "+dtoc( dEXE )+;
" "+FWVERSION+" "+VERSION() PIXEL of oDLG COLOR "N+/W"
oDlg:aControls[ 2 ]:lTransparent = .t.
If .not. File(cOldDefa+"\YachtCoveHelp.Pdf")
Saying := "The Help file "+cOldDefa+"\YachtCoveHelp.Pdf is not Available"
MsgInfo( Saying )
Else
oSay:lWantClick = .T.
oSay:bLClicked = { | | SHELLEXECUTE(nil,"open", cOldDefa+"\YachtCoveHelp.Pdf",0,0,1) }
oSay:oCursor = oHAND
Endif
ACTIVATE DIALOG oDLG CENTERED
oBru:End()
RETURN(NIL)
Re: Test for a .Pdf reader
Posted:
Wed Nov 09, 2011 11:25 pm
by ukoenig
Rick,
try to check from the Registry :
Have a look at Samples : Testreg.prg, Testreg2.prg, Testreg3.prg
You can try checking the registry for this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader
If it's there, it's a pretty good chance that it's installed.
If you want to go all out, use the value in the
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\<version>\InstallPath
key to make sure the executable is there. <version> could vary
so you'll have to use the RegEnumKeyEx API call to get the exact key name.
I'm assuming all versions of Reader use the same registry structure.- Code: Select all Expand view
#include "fivewin.ch"
#define HKEY_LOCAL_MACHINE 2147483650
FUNCTION MAIN()
local nHandle
IF RegOpenKey( HKEY_LOCAL_MACHINE,;
"SOFTWARE\Adobe\Acrobat Reader\", @nHandle ) == 0
RegCloseKey( nHandle )
MsgAlert( "Acrobat Reader installed !" )
ELSE
MsgAlert( "Can't open this key" )
ENDIF
RETURN NIL
Best Regards
Uwe
Re: Test for a .Pdf reader
Posted:
Wed Nov 09, 2011 11:50 pm
by ADutheil
You can try to discover if .pdf is associated with any application:
FUNCTION TestPdfReader
LOCAL lRetu := .F.
LOCAL hKey, cName, uValue, n := 0
LOCAL aKeys := {}
#define HKEY_LOCAL_MACHINE 2147483650
RegOpenKey( HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\.pdf", @hKey )
WHILE RegEnumValue( hKey, n++, @cName, @uValue ) = 0
aAdd( aKeys, { cName, uValue } )
ENDDO
RegCloseKey( hKey )
IF ( n := aScan( aKeys, { |x| x[ 1 ] = "Content Type" .AND. x[ 2 ] = "application/pdf" } ) ) > 0
lRetu := .T.
ENDIF
RETURN ( lRetu )
Re: Test for a .Pdf reader
Posted:
Thu Nov 10, 2011 7:55 pm
by Rick Lipkin
Andre
I tried your code and it always returns .f. .. it seems the reg key is never evaluated and never hits the array loop.
I have Foxit .pdf reader installed and here is the screenshot of the Registry key ..
Using FWH 9.10 ..
Here is the code .. and again, I never get any values because the program never hits the do while loop.
Rick
- Code: Select all Expand view
// --
#include "FiveWin.ch"
//-------------------
Func Main()
Local lPdf := .f.
lPdf := TestPdfReader()
msginfo( lPdf )
Return(lpdf )
//----------------------
FUNCTION TestPdfReader
LOCAL lRetu := .F.
LOCAL hKey, cName, uValue, n := 0
LOCAL aKeys := {}
#define HKEY_LOCAL_MACHINE 2147483650
RegOpenKey( HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\.pdf", @hKey )
Do While RegEnumValue( hKey, n++, @cName, @uValue ) = 0
msginfo( cname ) // never gets here
msginfo( uvalue )
aAdd( aKeys, { cName, uValue } )
ENDDO
RegCloseKey( hKey )
IF ( n := aScan( aKeys, { |x| x[ 1 ] = "Content Type" .AND. x[ 2 ] = "application/pdf" } ) ) > 0
lRetu := .T.
ENDIF
RETURN ( lRetu )
Re: Test for a .Pdf reader
Posted:
Thu Nov 10, 2011 8:25 pm
by Rick Lipkin
I noticed searching thru the forum that there was a change to Regedit.c in version 9.10 ..
- Code: Select all Expand view
//----------------------------------------------------------------------------//
HB_FUNC( REGOPENKEY ) // ( nkey, cSubKey, @nHandle ) --> nResult
{
HKEY hKey = ( HKEY ) hb_parnl( 1 );
HKEY hResult;
#ifndef UNICODE
hb_retnl( RegOpenKey( hKey, hb_parc( 2 ), &hResult ) );
hb_stornl( ( LONG ) hResult, 3 );
#else
LPWSTR pW = AnsiToWide( hb_parc( 2 ) );
hb_retnl( RegOpenKeyEx( hKey, pW, 0, ( REGSAM ) hb_parnl( 3 ), &hResult ) );
hb_stornl( ( LONG ) hResult, 3 );
hb_xfree( pW );
#endif
}
How can I re-compile this code into my regedit.c or include it in my application ??
Thanks
Rick Lipkin
Re: Test for a .Pdf reader
Posted:
Thu Nov 10, 2011 11:28 pm
by ADutheil
I use Foxit reader too and the function works OK for me with windows 7 64bits FHW11.10 BCC582 HB 3.0.
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 12:51 am
by ADutheil
Just tested on another computer with Windows XP SP3 and it worked OK. You can download the program I used to test the function from
http://www.mediafire.com/?khtcahygiy7gt9y
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 10:53 am
by ukoenig
André,
Works (tested) on VISTA with installed Acrobat 9.0.
Best Regards
Uwe
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 11:39 am
by ADutheil
Rick,
if you want to rewrite the regopenkey() function you can try to add the folowing code to your system:
#pragma BEGINDUMP
HB_FUNC( REGOPENKEY ) // ( nkey, cSubKey, @nHandle ) --> nResult
{
HKEY hKey = ( HKEY ) hb_parnl( 1 );
HKEY hResult;
#ifndef UNICODE
hb_retnl( RegOpenKey( hKey, hb_parc( 2 ), &hResult ) );
hb_stornl( ( LONG ) hResult, 3 );
#else
LPWSTR pW = AnsiToWide( hb_parc( 2 ) );
hb_retnl( RegOpenKeyEx( hKey, pW, 0, ( REGSAM ) hb_parnl( 3 ), &hResult ) );
hb_stornl( ( LONG ) hResult, 3 );
hb_xfree( pW );
#endif
}
#pragma ENDDUMP
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 2:30 pm
by Rick Lipkin
Andre
I thought of just adding that snipit to my program as well and I got all kinds of errors .. not a .c programmer here ..
I tried your modification with similar results
Rick Lipkin
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 3:03 pm
by anserkk
Please add these lines:
- Code: Select all Expand view
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
Regards
Anser
Re: Test for a .Pdf reader
Posted:
Fri Nov 11, 2011 5:42 pm
by Rick Lipkin
Anser ..
Thank you !! .. everything works and I am now getting registry results !
Rick Lipkin