Running a Windows file

run[ex]()

Run a Windows file


SYNTAX

run[ex](filename)

run[ex](filename, verb, params, dir, show)

Run the Windows file specified in filename, using the application associated with the file type. The function can also be used to run an installed Windows executable program without the need to know its location.

The first syntax, in which only the file name is specified, runs the file using the default values for verb, params, dir and show.

If any non-default values are required, the second syntax must be used. It provides the following options:

verb

The action to be taken (e.g. open, edit, print). Refer to the application’s documentation for a list of possible values. Use 0 for the default action.

params

Parameters. Not all applications accept parameters; see the application documentation for details. Use 0 for the default parameters.

dir

The directory in which the command is to start. Use 0 for the application default.

show

The mode in which the application is to start. This determines the application window’s size and position, and whether or not it is activated, minimised or maximised. The valid options are defined as Activation options in <sculptor.h>.The default is AA_SHOWNORMAL (activate and show in normal size and position).

The run() function maps to the Windows function ShellExecute(). This should be used if the calling program exits immediately after calling the function. If the program does not exit, it may regain focus and lie on top of the called application.

The runex() function maps to the Windows function ShellExecuteEx(). This should be used if the calling program does not exit after calling the function. If it does exit, the new application may open with a blank document instead of the supplied document. This appears to be an issue in the Windows API.

The function returns 0 if successful, or a non-zero value if it fails.


EXAMPLE

  1. This example opens the file “readme.txt”, using the application associated with .txt files, and using defaults for all arguments except the last, which causes the window to be maximised. The calling program does not exit after calling the function, and so the runex version of the function is used:

    runex("readme.txt", 0, 0, 0, AA_SHOWMAXIMISED)
    
  2. Run Microsoft Word, opening the program with a blank document. Word is an installed Windows application, and so there is no need to specify its location:

    run("winword.exe")
    

RELATED TOPICS

File and directory handling functions