作者:
陆岛工作室
type
TExecState = (esNormal, esMinimized, esMaximized, esHidden);
function ExecuteFileWait(Handle: HWND; const FileName, Params, StartDir: string; InitialState: TExecState): Integer;
{
Handle: 传入当前窗口或 Applicaton 的句柄
FileName: 需要传入的文件名
Params: 执行文件所带的参数
StartDir: 执行文件启动路径
InitialState: 窗口显示模式
}
实现代码如下:
{ExecuteFileWait}
functionExecuteFileWait(Handle:HWND;constFileName,Params,StartDir:string;InitialState:TExecState):Integer;
const
ShowCommands:array[TExecState]ofLongInt=(SW_SHOWNORMAL,SW_MINIMIZE,SW_SHOWMAXIMIZED,SW_HIDE);
var
Info:TShellExecuteInfo;
ExitCode:DWORD;
FActive:HWND;
begin
FillChar(Info,SizeOf(Info),0);
Info.cbSize:=SizeOf(TShellExecuteInfo);
withInfodo
begin
fMask:=SEE_MASK_NOCLOSEPROCESS;
Wnd:=Application.MainForm.Handle;
lpFile:=PChar(FileName);
lpParameters:=PChar(Params);
lpDirectory:=PChar(StartDir);
nShow:=ShowCommands[InitialState];
end;
FActive:=GetActiveWindow;
ifShellExecuteEx(@Info)then
begin
EnableWindow(Handle,False);
repeat
Application.ProcessMessages;
GetExitCodeProcess(Info.hProcess,ExitCode);
until(ExitCode<>STILL_ACTIVE)orApplication.Terminated;
EnableWindow(Handle,True);
ShowWindow(Handle,SW_SHOW);
SetActiveWindow(FActive);
SetForegroundWindow(FActive);
Result:=ExitCode;
end
elseResult:=-1;
end;
示范:
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
阅读
好看
已推荐到看一看
你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
取消
分享想法到看一看
确定
最多200字,当前共字