我的程序通过FindWindow和SendMessage控制一个第三方的程序,这个程序是Windows界面程序,不是命令行程序。
这个是启动那个第三方程序的代码,设置SW_HIDE和CREATE_NO_WINDOW都无效,界面还是出现。
si.wShowWindow = SW_HIDE;
if(!CreateProcess(NULL, // No module name (use command line).
"WSD", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
TRUE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi)) // Pointer to PROCESS_INFORMATION structure.
我又试了在FindWindow之后,调用ShowWindow(SW_HIDE),可以隐藏主窗口,但新弹出的窗口如文件打开对话框和一些MessageBox还是会弹出来。而且这样做,被隐藏的窗口也会有个明显的闪动,不要。
哪位有更好的解决办法,给些建议吧。
用shellexecute吧,完全满足要求。
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c://MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);