gpt4 book ai didi

c++ - mingw-w64 如何在打开外部应用程序时停止显示控制台

转载 作者:行者123 更新时间:2023-11-28 06:46:33 24 4
gpt4 key购买 nike

我正在尝试编写一个应用程序来打开另一个应用程序并自行关闭,因此当外部应用程序打开时我不需要控制台

这是我到目前为止尝试过的:

system("cmd.exe /c application.exe"); //console shows, application opens, console wait

system("start \"\" application.exe"); //console shows, application opens, console close

//console does not show but neither the application (I can see it in task manager)
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));
CreateProcess(0, "application.exe", 0, 0, FALSE, 0, 0, 0, &si, &pi);

//console does not show but neither the application (I can see it in task manager)
WinExec("application.exe", SW_HIDE);

这是我编译的方式:

g++ -o "launcher" "launcher.cpp" -mwindows

最佳答案

这是一些对我有用的代码来实现你的目标:

// Declare and initialize process blocks
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;

memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

// Call the executable program
TCHAR cmd[] = myCommandText;

int result = ::CreateProcess(NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInformation);

在此上下文中,myCommandText 是一个控制台命令

关于c++ - mingw-w64 如何在打开外部应用程序时停止显示控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24894507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com