简体   繁体   中英

How to launch console application using CreateProcess with Minimized main window

I have a native c++ windows application that is launching two child processes using the following code -

if (!CreateProcess(NULL, // No module name (use command line)
    cmdLine, // szCmdline, // Command line
    NULL, // Process handle not inheritable
    NULL, // Thread handle not inheritable
    false, // Set handle inheritance to FALSE
    CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS // Process Create Flags
    NULL, // Use parent's environment block
    NULL, // workingDir, // Use parent's starting directory
    &si, // Pointer to STARTUPINFO structure
    &pi) // Pointer to PROCESS_INFORMATION structure

with all parameters in STARTUPINFO block 0. This code works fine in launching the processes. However, I need to be able to launch the windows c++ console applications with their windows minimized.

If I add CREATE_NO_WINDOW to the Process Create Flags, I can launch the processes without any windows. This will be unacceptable.

In my research, there does not appear to be a way force a console application to open in a minimized mode. Is this correct?

Yes, I know that I could minimize the child application windows from within their own process, however, the other programmers on the team prefer not to do this.

You need to specify in the STARTUPINFO structure that you want your console window to be initially minimized:

ZeroMemory(&si);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MINIMIZE;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM