比如在窗体里单击一个按钮调用一个可执行程序(C:\a.exe),然后在该程序关闭后返回窗体界面.请给出具体代码。
解决方案 »
- delphi鼠标移动到控件时按F4键响应其他事件
- 问一个日期参数的小问题
- 对RzShellList或RzShellList熟悉的请进
- 想开发一个系统,遇到一个难题,高手给个建议!
- 请教关于使用TAPDCOMPORT控件的问题
- 用数据库还是文本文件直接操作呢?最好有些具体步骤,菜菜菜啊!!!
- 请问如何对猫的语音部分进行编程?
- 简单问题:请问如何限制窗口的最小范围的大小?
- wwDBGrid的标题栏能在排序时显示一个正三角或倒三角图标吗
- 菜鸟求助引用类型
- (ado连库adoquery查询)label控件可以显示数据库中的字段内容吗? 怎样实现?怎样只显示一条记录内容(不用grid件,自己做显示界面)?
- 我在用Delphi7时,不想让菜单显示加速字符,可是程序运行后总是自动加上加速字符,又没办法去掉,请教高手怎么解决?
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 }
true, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then Result := INFINITE {-1} else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
WinExecAndWait32('c:\a.exe', SW_NORMAL);
end;
function Execute(const Command: string; bWaitExecute: Boolean; bShowWindow: Boolean; PI: PProcessInformation): Boolean;
var
StartupInfo : TStartupInfo;
ProcessInformation: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
if bShowWindow then
wShowWindow := SW_NORMAL
else
wShowWindow := SW_HIDE;
end;
Result := CreateProcess(nil, PChar(Command),
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
StartupInfo, ProcessInformation);
if not Result then Exit;
if bWaitExecute then
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
if Assigned(PI) then
Move(ProcessInformation, PI^, SizeOf(ProcessInformation));
end;