FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Test for a .Pdf reader
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Test for a .Pdf reader
Posted: 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 (fw): Select all Collapse
//-------------------------
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)
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Test for a .Pdf reader
Posted: 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 (fw): Select all Collapse
#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 :-)
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.
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Test for a .Pdf reader
Posted: 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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test for a .Pdf reader
Posted: Thu Nov 10, 2011 07: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 ..




Here is the code .. and again, I never get any values because the program never hits the do while loop.

Rick

Code (fw): Select all Collapse
// --

#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 )
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test for a .Pdf reader
Posted: Thu Nov 10, 2011 08:25 PM
I noticed searching thru the forum that there was a change to Regedit.c in version 9.10 ..

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
 
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
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Test for a .Pdf reader
Posted: 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
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Test for a .Pdf reader
Posted: 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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Test for a .Pdf reader
Posted: 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.
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Test for a .Pdf reader
Posted: 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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test for a .Pdf reader
Posted: Fri Nov 11, 2011 02: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

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Test for a .Pdf reader
Posted: Fri Nov 11, 2011 03:03 PM
Please add these lines:

Code (fw): Select all Collapse
#pragma BEGINDUMP

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


Regards
Anser
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test for a .Pdf reader
Posted: Fri Nov 11, 2011 05:42 PM

Anser ..

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

Rick Lipkin

Continue the discussion