Forum Home
Press F1
 
Thread ID: 15258 2002-02-02 08:03:00 Delphi 3 & Executing programs Guest (0) Press F1
Post ID Timestamp Content User
33996 2002-02-02 08:03:00 I am trying to use the ShellExecute() function provided in shell32.dll, but I'll be damned if I can figure out how, would someone please be able to give me a source code fragment to do this? The DLL needs to firstly be imported and then I get the impression an alias is setup for the function I want to suit delphi calling procedures, and then finally I hope I can just call the function. Exactly how to do this......I am not sure, so please, anyone?
Thanks.
Guest (0)
33997 2002-02-02 09:28:00 Under Delphi, it's recommended you use ExecuteFile instead of ShellExecute.

ExecuteFile is available through the FMXUtils unit, so you'll need to add that. Passing the name of an executable will run it.

Here's a code snippet to indicate the syntax etc. (No warranty provided with this sucker, so pse don't flame me if there's a typo or two lurking within...) :-)

($R *.DFM)

function ExecuteFile(const, FileName, Params, Dir: String; ShowCmd: Integer): THandle;

begin

Result := ShellExecute(Application.MainForm.Handle, nil, PChar(FileName), PChar(Params), PChar(Dir), ShowCmd);

end;

Procedure TMAinForm.RunBitBtnClick(Sender: TObject);

begin

with DirDlgForm do

if ShowModal = mrOK then

if ExecuteFile(FilenameEdit.Text, '',

DirectoryListBox.Directory, SW_SHOW) <= 32 then

MessageDlg('Unable to open program.',

mtError, [mbOK], 0)

else Application.Minimize;
end;

I've also used it quite simply as a hard-wired reference to one of Windows' applets I know to always be available. (Not a good idea I know, but it wasn't for distribution so I let myself off with a stern warning!)

That snippet follows.

procedure TFormPuz.VolumeControls1Click(Sender: TObject);

begin

ExecuteFile('C:\Windows\Sndvol32.exe', '', '', SW_SHOWNORMAL);

end;

It opens the Windows Volume Control applet. You might try it out as a test...remember to protect the call with a 'Try Finally' block when you use it for real.

Hope that helps.
Guest (0)
33998 2002-02-03 07:37:00 Awesome, thanks. I'm now looking to find FMXUtils, so if you know a good site to find it then that would be really nice. I've just tried DelphiCity but they don't appear to have it, despite all expectation. Guest (0)
1