Test for a .Pdf reader

Test for a .Pdf reader

Postby Rick Lipkin » Wed Nov 09, 2011 10:11 pm

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)
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test for a .Pdf reader

Postby ukoenig » Wed Nov 09, 2011 11:25 pm

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 :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Test for a .Pdf reader

Postby ADutheil » Wed Nov 09, 2011 11:50 pm

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 )
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Test for a .Pdf reader

Postby Rick Lipkin » Thu Nov 10, 2011 7:55 pm

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 ..

Image


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 )
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test for a .Pdf reader

Postby Rick Lipkin » Thu Nov 10, 2011 8:25 pm

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test for a .Pdf reader

Postby ADutheil » Thu Nov 10, 2011 11:28 pm

I use Foxit reader too and the function works OK for me with windows 7 64bits FHW11.10 BCC582 HB 3.0.
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Test for a .Pdf reader

Postby ADutheil » Fri Nov 11, 2011 12:51 am

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
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Test for a .Pdf reader

Postby ukoenig » Fri Nov 11, 2011 10:53 am

André,

Works (tested) on VISTA with installed Acrobat 9.0.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Test for a .Pdf reader

Postby ADutheil » Fri Nov 11, 2011 11:39 am

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
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Test for a .Pdf reader

Postby Rick Lipkin » Fri Nov 11, 2011 2:30 pm

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

Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test for a .Pdf reader

Postby anserkk » Fri Nov 11, 2011 3:03 pm

Please add these lines:

Code: Select all  Expand view
#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>


Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Test for a .Pdf reader

Postby Rick Lipkin » Fri Nov 11, 2011 5:42 pm

Anser ..

Thank you !! .. everything works and I am now getting registry results !

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 95 guests