|
Executing an external application
Copyright © 2000 Ernesto
De Spirito
ShellExecute
Many times we need to execute another program from ours. To do this, we can use
the ShellExecute function declared in the ShellAPI unit.
The syntax is:
ShellExecute(Handle, Operation, FileName, Params, Folder, ShowCmd)
Return value: If ShellExecute succeeds, it returns a value of
type HINST (a LongWord) with the instance handle
of the application that was run, or the handle of a dynamic data
exchange (DDE) server application. If it fails, it returns an error
code from 0 to 32.
Examples
uses ShellAPI;
...
if ShellExecute(Form1.Handle, nil,
'c:\windows\general.txt', nil, nil, SW_SHOW) <= 32 then
Application.MessageBox('Couldn''t execute the application',
'Error', MB_ICONEXCLAMATION);
ShellExecute(Form1.Handle, nil, 'c:\windows\notepad.exe',
'c:\windows\general.txt', nil, SW_SHOWMAXIMIZED);
ShellExecute(Form1.Handle, 'open', 'c:\windows\notepad.exe',
'general.txt', 'c:\windows', SW_SHOWNORMAL);
ShellExecute(Form1.Handle, nil, PChar(fname + '.txt'),
nil, nil, SW_MAXIMIZE);
ShellExecute(Form1.Handle, nil, 'c:\windows\notepad.exe',
nil, nil, SW_SHOWNORMAL);
Note
An application called by ShellExecute will run asynchronously, that
is, the execution of our application continues without waiting the end
of the called application that will run simultaneously.
If you need to run an application synchronously, please
read Waiting till an application ends.
|