How to open a file with the system default program?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to open a file with the system default program?

Gruenewald, Tom




Hello.
How can I open a file (e.g. test.csv) with the defined system default
program (e.g. MS Excel) depending on its file extension?
If no default program is defined and no "Open with..." dialog will be
displayed, I like to handle this by displaying the file content in a small
ST editor.
Thank you for your help.

Best regards,
Tom Grünewald

Reply | Threaded
Open this post in threaded view
|

Re: How to open a file with the system default program?

Josef Springer
Hi Tom,

use (OSSystemSupport concreteClass) CreateProcess: nil arguments: 'cmd /C "your file"'
The file extension must be registered in Windows !

Signature mit freundlichen Grüßen / best regards,
Josef

Postal
Address
[hidden email]
Orlando-di-Lasso Str. 2
D-85640 Putzbrunn
Phone
Office
+49 (0)89 600 6920


Phone
Fax
+49 (0)89 600 69220


Web
Web
http://www.joops.com



JOOPS
-- the software company --

 


Gruenewald, Tom wrote:



Hello.
How can I open a file (e.g. test.csv) with the defined system default
program (e.g. MS Excel) depending on its file extension?
If no default program is defined and no "Open with..." dialog will be
displayed, I like to handle this by displaying the file content in a small
ST editor.
Thank you for your help.

Best regards,
Tom Grünewald



Reply | Threaded
Open this post in threaded view
|

RE: How to open a file with the system default program?

Steven Kelly
In reply to this post by Gruenewald, Tom
Signature

Or if you want it to work with URLs, in Win 9x, and in XP/2000/NT if the user has turned off command extensions:

 

'nt' = ((OSHandle currentPlatformID tokensBasedOn: Character space) at: 3) asLowercase

 ifTrue: [prefix := 'cmd /x /c start "" ']

 ifFalse: [prefix := 'start '].

OSSystemSupport concreteClass CreateProcess: nil arguments: prefix, aString.

 

where aString should be surrounded by double quotes if it contains spaces.

 

HTH,

Steve

 

-----Original Message-----
From: Josef Springer [mailto:[hidden email]]
Sent: 13 November 2006 18:09
To: Gruenewald, Tom
Cc: [hidden email]
Subject: Re: How to open a file with the system default program?

 

Hi Tom,

use (OSSystemSupport concreteClass) CreateProcess: nil arguments: 'cmd /C "your file"'
The file extension must be registered in Windows !


mit freundlichen Grüßen / best regards,
Josef

Postal

Address

[hidden email]

Orlando-di-Lasso Str. 2

D-85640 Putzbrunn

Phone

Office

+49 (0)89 600 6920

 

 

Phone

Fax

+49 (0)89 600 69220

 

 

Web

Web

http://www.joops.com

 

 

 

JOOPS

-- the software company --


 



Gruenewald, Tom wrote:




Hello.
How can I open a file (e.g. test.csv) with the defined system default
program (e.g. MS Excel) depending on its file extension?
If no default program is defined and no "Open with..." dialog will be
displayed, I like to handle this by displaying the file content in a small
ST editor.
Thank you for your help.

Best regards,
Tom Grünewald

 

Reply | Threaded
Open this post in threaded view
|

Re: How to open a file with the system default program?

Mark Pirogovsky-3
In reply to this post by Gruenewald, Tom
Load Windows Goodies parcel. and look at the #openFile: method there.

You probably will need to modify it a bit as follows:

openFile: aFilename
       
"self openFile: 'http://www.yahoo.com'"
"self openFile: 'team1.pdf'"

        | xif hwnd |
        xif := self new.
        hwnd := nil.
"the mod"
        Dialog defaultParentWindow
                ifNotNil: [:aWin | hwnd := xif HWND cast: aWin windowHandle].
"/the mod"
        ^xif
                ShellExecute: hwnd
                with: 'open'
                with: aFilename asString
                with: nil
                with: nil
                with: xif SW_SHOWNORMAL

if file has an association you will get a handle to the process.

HTH

--Mark

Gruenewald, Tom wrote:

>
>
>
> Hello.
> How can I open a file (e.g. test.csv) with the defined system default
> program (e.g. MS Excel) depending on its file extension?
> If no default program is defined and no "Open with..." dialog will be
> displayed, I like to handle this by displaying the file content in a small
> ST editor.
> Thank you for your help.
>
> Best regards,
> Tom Grünewald
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How to open a file with the system default program?

Mark Pirogovsky-3
My mouse was to quick.

Here is additional info for the return values:

Returns
The return value is the instance handle of the application that was
opened or printed, if the function is successful. (This handle could
also be the handle of a DDE server application.) A return value less
than or equal to 32 specifies an error.

if for some reason the command did not succed you can examine the error
codes :

Errors
The ShellExecute() function returns the value 31 if there is no
association for the specified file type or if there is no association
for the specified action within the file type. The other possible error
values are as follows: Value          Meaning
---------------------------------------------------------------------------

    0             System was out of memory, executable file was corrupt, or
                  relocations were invalid.

    2             File was not found.

    3             Path was not found.

    5             Attempt was made to dynamically link to a task, or there
                  was a sharing or network-protection error.

    6             Library required separate data segments for each task.

    8             There was insufficient memory to start the application.

   10             Windows version was incorrect.

   11             Executable file was invalid. Either it was not a Windows
                  application, or there was an error in the .exe image.

   12             Application was designed for a different operating system.

   13             Application was designed for MS-DOS 4.0.

   14             Type of executable file was unknown.

   15             Attempt was made to load a real-mode application
                 (developed for an earlier version of Windows).

   16             Attempt was made to load a second instance of an
                  executable file containing multiple data segments that
                  were not marked read-only.

   19             Attempt was made to load a compressed executable file. The
                  file must be decompressed before it can be loaded.

   20             Dynamic-link library (DLL) file was invalid. One of the
                  DLLs required to run this application was corrupt.

   21             Application requires Microsoft Windows 32-bit extensions.
                               



Mark Pirogovsky wrote:

> Load Windows Goodies parcel. and look at the #openFile: method there.
>
> You probably will need to modify it a bit as follows:
>
> openFile: aFilename
>    
> "self openFile: 'http://www.yahoo.com'"
> "self openFile: 'team1.pdf'"
>
>     | xif hwnd |
>     xif := self new.
>     hwnd := nil.
> "the mod"
>     Dialog defaultParentWindow
>         ifNotNil: [:aWin | hwnd := xif HWND cast: aWin windowHandle].
> "/the mod"
>     ^xif
>         ShellExecute: hwnd
>         with: 'open'
>         with: aFilename asString
>         with: nil
>         with: nil
>         with: xif SW_SHOWNORMAL
>
> if file has an association you will get a handle to the process.
>
> HTH
>
> --Mark
>
> Gruenewald, Tom wrote:
>
>>
>>
>>
>> Hello.
>> How can I open a file (e.g. test.csv) with the defined system default
>> program (e.g. MS Excel) depending on its file extension?
>> If no default program is defined and no "Open with..." dialog will be
>> displayed, I like to handle this by displaying the file content in a
>> small
>> ST editor.
>> Thank you for your help.
>>
>> Best regards,
>> Tom Grünewald
>>
>>
>>
>
>
>