• Welcome to Jose's Read Only Forum 2023.
 

Tip - Bypass file association and fire the app YOU want on specific file ext

Started by Patrice Terrier, May 11, 2007, 04:32:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

 
This one fires the system "Open file with" to open a specific file extension with the application you want, instead of using the default associated one.

The main subroutine name is : "zOpenThisFileWith"


#COMPILE EXE

%NULL                                           = 0
%MAX_PATH                                       = 260  ' max. length of full pathname
%SW_SHOW                                        = 5

DECLARE FUNCTION GetCurrentDirectory LIB "KERNEL32.DLL" ALIAS "GetCurrentDirectoryA" (BYVAL nBufferLength AS LONG, lpBuffer AS ASCIIZ) AS LONG
DECLARE FUNCTION ShellExecute LIB "SHELL32.DLL" ALIAS "ShellExecuteA" (BYVAL hwnd AS DWORD, lpOperation AS ASCIIZ, lpFile AS ASCIIZ, lpParameters AS ASCIIZ, lpDirectory AS ASCIIZ, BYVAL nShowCmd AS LONG) AS DWORD

$Anti = "\"

' Returns current Disk and Path
SUB zDskPath (Dsk$, Path$)
'   Dsk$ and Path$ are ready to be concatened with a filename
'   Dsk$ and Paths correspond to the current directory
    LOCAL zTmp AS ASCIIZ * %MAX_PATH
    IF GetCurrentDirectory(BYVAL SIZEOF(zTmp), zTmp) THEN
       Dsk$ = LEFT$(zTmp, 2)
       Path$ = RTRIM$(MID$(zTmp, 3), ANY CHR$(0,92)) + $Anti
    END IF
END SUB

' Splits a full path name, and return the current disk and directory
SUB zSplitN (BYVAL FullName$, PathName$, FilName$)
' If no path is specified then the current directory is being used.
    PathName$ = "": FilName$ = ""
    Length& = LEN(FullName$)
    IF Length& THEN
       CALL zDskPath(Dsk$, ThisPath$): FilName$ = FullName$
       So& = INSTR(-1, FullName$, $Anti)
       IF So& THEN
          PathName$ = LEFT$(FullName$, So&)
       ELSE
          So& = INSTR(FullName$, ":")
       END IF
       IF PathName$ = Dsk$ OR LEN(PathName$) = 0 THEN
          PathName$ = Dsk$ + ThisPath$
       END IF
       IF So& THEN FilName$ = MID$(FullName$, So& + 1, Length& - So&)
    END IF
END SUB

SUB zOpenThisFileWith(BYVAL FullPathName$)

    CALL zSplitN (FullPathName$, PathName$, FilName$)
    TrimPath$ = RTRIM$(PathName$, "\")
    FireThis$ = "shell32.dll,OpenAs_RunDLL " + FullPathName$
    Ret& = ShellExecute(BYVAL %NULL, "open", "rundll32.exe", _
                        BYVAL STRPTR(FireThis$), BYVAL STRPTR(TrimPath$), %SW_SHOW)
END SUB

FUNCTION PBMAIN() AS LONG

    FullPathName$ = "c:\Mail_IN\PJ\d1a674_0080000006.png" ' <--- adapt this to your case

    CALL zOpenThisFileWith(FullPathName$)

END FUNCTION

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com