home *** CD-ROM | disk | FTP | other *** search
- unit Drwsutl1;
-
- interface
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl;
-
- function ShellExec(const PathStr, CmdStr, DirStr: string;
- PrintIt: boolean; Show: word; Wait: boolean): boolean;
- implementation
-
- { This function is from Delphi How To Copyright 1995 Waite Group Press }
- function ShellExec(const PathStr, CmdStr, DirStr: string;
- PrintIt: boolean; Show: word; Wait: boolean): boolean;
- var
- Inst: THandle;
- Path, CmdLine, Dir: PChar;
- Op: array[0..5] of Char;
- AppWin: hWnd;
- Valid: Bool;
- begin
- if PrintIt then StrPCopy(Op, 'print') else StrPCopy(Op, 'open');
- { Get memory for PChars }
- GetMem(Path, Length(PathStr)+1);
- GetMem(CmdLine, Length(CmdStr)+1);
- GetMem(Dir, Length(DirStr)+1);
- try
- { Copy strings to PChars }
- StrPCopy(Path, PathStr);
- StrPCopy(CmdLine, CmdStr);
- StrPCopy(Dir, DirStr);
- { Execute file }
- Inst := ShellExecute(0, Op, Path, CmdLine, Dir, Show);
- { If 32 or less, an error occurred }
- if Inst <= 32 then Result := False else
- begin
- if Wait then
- begin
- { Loop while program is running }
- while GetModuleUsage(Inst) <> 0 do
- Application.ProcessMessages;
- { Acknowledge error from last iteration of loop }
- OutputDebugString('--> Please ignore the previous error'#10#13);
- end;
- Result := True;
- end;
- finally
- { Ensure memory is freed }
- FreeMem(Path, Length(PathStr)+1);
- FreeMem(CmdLine, Length(CmdStr)+1);
- FreeMem(Dir, Length(DirStr)+1);
- end;
- end;
-
-
- end.
-