system函数隐藏控制台窗口

梦想游戏人
目录:
C/C++

MFC等 执行system函数的时候会闪烁控制台窗口

创建进程的时候隐藏窗口即可

void   Utils::system_hide_cmd(const string &cmd)
{
	WCHAR path[MAX_PATH];
	GetSystemDirectoryW(path, MAX_PATH);
	string x = Utils::toAscii(path);
	x += "\\cmd.exe";

	SHELLEXECUTEINFOW ShExecInfo = { 0 };
	ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
	ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
	ShExecInfo.hwnd = NULL;
	ShExecInfo.lpVerb = NULL;
	ShExecInfo.lpFile = Utils::toUnicode(x.c_str());
	ShExecInfo.lpParameters = Utils::toUnicode(cmd.c_str());
	ShExecInfo.nShow = SW_HIDE;
	ShExecInfo.hInstApp = NULL;
	ShellExecuteExW(&ShExecInfo);
	WaitForSingleObject(ShExecInfo.hProcess, INFINITE);////wait for exit 

}
Scroll Up