我必须为一个exe文件开发一个启动器,但我在关闭主窗体时遇到了一些问题。
我想保持打开可执行文件,但关闭窗体。我成功地执行了应用程序,在.exe打开后,.exe被执行,表单被“关闭”。这几乎就是我想要的,但launcher.exe在windows任务管理器中仍然是活动的。
以下是执行.exe的过程:
procedure TForm2.LancerVersion(aExe: String);
var
SEInfo: TShellExecuteInfo;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(aExe);
nShow := SW_SHOWNORMAL;
end;
ShellExecuteEx(@SEInfo);
if Blight then
begin
free;
Close; **//HERE I WOULD LIKE TO CLOSE CLEANLY MY FORM**
end
else
hide;
end;这是用于结束的自定义过程:
procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if BClose then
begin
Canclose := false;
Bshow := false;
end;
Canclose := true; **//IT GOES HERE AFTER CLOSE IS CALLED**
end;我之所以编写这个自定义过程,是因为有时我只是想在单击X窗口的按钮时,将窗体隐藏在参数函数中的托盘图标中。所以,不要关心第一个条件"if Bclose then“。
我确保将我在FormCreate中创建的FormDestroy中的所有对象都释放出来,但什么也没做,这个过程会持续下去……
如果你能帮我或者只是看看我的问题,我将不胜感激。提前谢谢你..
发布于 2014-07-04 21:16:22
这是一个小的工作SSCCE:
procedure TForm1.Button1Click(Sender: TObject);
var
SEInfo: TShellExecuteInfo;
ExecuteFile: string;
begin
ExecuteFile := 'notepad.exe';
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do
begin
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile);
nShow := SW_SHOWNORMAL;
end;
Win32Check(ShellExecuteEx(@SEInfo));
Close;
end;问题在于您在过程中调用了Free,请不要这样做。
https://stackoverflow.com/questions/24574912
复制相似问题