本文整理自网络,侵删。
hApp: Cardinal;
function StartApp(apchOperation, apchFileName, apchParameters, apchDirectory: PChar; awrdShowCmd: Word): Cardinal;var lseiInfo: TShellExecuteInfo;begin Result := 0;
FillChar(lseiInfo, SizeOf(lseiInfo), Chr(0)); lseiInfo.cbSize := SizeOf(lseiInfo); lseiInfo.fMask := SEE_MASK_NOCLOSEPROCESS; lseiInfo.lpVerb := apchOperation; lseiInfo.lpFile := apchFileName; lseiInfo.lpParameters := apchParameters; lseiInfo.lpDirectory := apchDirectory; lseiInfo.nShow := awrdShowCmd;
if Boolean(ShellExecuteEx(@lseiInfo)) then Result := lseiInfo.hProcess;end;
procedure DestroyProcess(hProcess: Cardinal);Var ovExitCode: LongWord;begin try if hProcess<>0 then begin GetExitCodeProcess(hProcess, ovExitCode); if (ovExitCode = STILL_ACTIVE) or (ovExitCode <> WAIT_OBJECT_0) then TerminateProcess(hProcess, ovExitCode); CloseHandle(hProcess); end; except end;end;
procedure TForm1.Button3Click(Sender: TObject);begin hApp := StartApp('open', 'd:\Workers.pdf', '', '', SW_SHOWNORMAL);end;
procedure TForm1.Button4Click(Sender: TObject);begin if hApp > 0 then DestroyProcess(hApp);end;
相关阅读 >>
Delphi winapi: setwindowtext - 设置窗口标题
Delphi xe 泛型数组和splitstring处理数据
pos、ansipos、fillchar在Delphi2010中unicode的问题
Delphi windows 编程[6] - 学习窗体生成的过程六: 最终的代码!
Delphi tms web core twebsocketclient
更多相关阅读请进入《Delphi》频道 >>