function WinExecAndWait32(FileName:String Visibility : integer): DWORD
var
zAppName:array[0..512] of char
zCurDir:array[0..255] of char
WorkDir:String
StartupInfo:TStartupInfo
ProcessInfo:TProcessInformation
begin
StrPCopy(zAppName,FileName)
GetDir(0,WorkDir)
StrPCopy(zCurDir,WorkDir)
FillChar(StartupInfo,Sizeof(StartupInfo),#0)
StartupInfo.cb := Sizeof(StartupInfo)
StartupInfo.dwFlags := STARTF_USESHOWWINDOW
StartupInfo.wShowWindow := Visibility
if not CreateProcess(
nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo { pointer to PROCESS_INF }
)
then Result := $FFFFFFFF else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE)
GetExitCodeProcess(ProcessInfo.hProcess,Result)
end
end
procedure TForm1.N9Click(Sender: TObject)
var i:integer
begin
WinExecAndWait32('PAS2 >tempc2.txt',0)
EXECUTEFILE('notepad.EXE','tempc2.txt','',sw_showmaximized)
end
方法一uses WinProcs
……
begin
WinExec(......)
……
end.
和调用Pascal库函数没什么两样。
方法二
用ShellExecute更好,在USES段加入SHELLAPI,使用时如:
执行"c:\myapp\myapp.exe"参数为"-s"
ShellExecute(handle,'open','c:\myapp\myapp.exe','-s','',SW_SHOWNORMAL)
第一个参数为父窗口句柄;
第二个参数为打开方式(OPEN,PRINT两种);
第三个参数为执行文件全路径;
第四个参数为执行文件参数;
第五个参数为执行文件开始运行时的初始目录;
第六个参数为为执行文件运行方式(SW_HIDE,SW_MAXIMIZE,SW_MINIMIZE,
SW_RESTORE,SW_SHOW,SW_SHOWDEFAULT,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,
SW_SHOWMINNOACTIVE,SW_SHOWNA,SW_SHOWNOACTIVATE,SW_SHOWNORMAL)
具体请看帮助。另外,如果为字符串参数,其中包含变量或运算的必需用PCHAR()函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)