run by Extension

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 873
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 132 times
Been thanked: 218 times

run by Extension

Post by AUGE_OHR »

when work on FTP Source i got to this Point

Code: Select all

   IF cExt = 'EXE' .OR. cExt = 'BAT' .OR. cExt = 'COM'
      _Execute( 0,, cFile,, cPath, 5 )
   ELSE
      cExe := GetOpenCommand( cExt )
      IF !EMPTY( cExe )
         cFile := cPath + '\' + cFile
         _Execute( 0,, cExe, IF( AT( " ", cFile ) > 0, '"' + cFile + '"', cFile ), cPath, 5 )
      ELSE
         MsgInfo( 'Error executing program!', "Alert" )
      ENDIF
   ENDIF
in GetOpenCommand() it search in Registry for App belong to Extension to "open" ... :roll:

but this is IMHO not need when use ShellExecute()
https://docs.microsoft.com/en-us/window ... llexecutea

now in c:\hmg.3.4.4\SOURCE\h_winapimisc.prg

Code: Select all

Function _Execute( nActiveWindowhandle , cOperation , cFile , cParaMeters , cDefault , nState )
	If ValType ( nActiveWindowhandle ) == 'U'
		nActiveWindowhandle := 0
	EndIf
	If ValType ( cOperation ) == 'U'
		cOperation := Nil
	EndIf
	If ValType ( cFile ) == 'U'
		cFile := ""
	EndIf
	If ValType ( cParaMeters ) == 'U'
		cParaMeters := Nil
	EndIf
	If ValType ( cDefault ) == 'U'
		 cDefault := Nil
	EndIf
	If ValType ( nState ) == 'U'
		 nState := 10 // SW_SHOWDEFAULT
	EndIf

	ShellExecute ( nActiveWindowhandle , cOperation , cFile , cParaMeters , cDefault , nState )
RETURN Nil
now look at this

Code: Select all

FUNCTION SHELLOPENFILE( cPath, cFILE, cPara ) 
LOCAL lSuccess
LOCAL Retvar   := .F.

   DEFAULT cPath TO ""
   DEFAULT cFILE TO ""
   DEFAULT cPara TO CURDIR()

   lSuccess := ShellExecute( 0, ;
                             "open", ;
                             cPath + cFILE, ;
                             cPara, ;
                             0, ;
                             SW_NORMAL )
it does NOT need EXE assign to File Extension.
2nd Parameter "lpOperation" is a "Verb" which can be "open","print" ... depend on File or Folder

so i correct Code this Way and get rid of Registry "C"-Code

Code: Select all

   IF cExt = 'EXE' .OR. cExt = 'BAT' .OR. cExt = 'COM'
      _Execute( 0,, cFile,, cPath, 5 )
   ELSEIF cExt = 'LNK'
      // LNK need to open other Way
   ELSE
      _Execute( 0,"open", '"' +cFile + '"', , cPath, 5 )
   ENDIF
have fun
Jimmy

Post Reply