Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 222
photo_tom Avatar asked Dec 07 '10 19:12

photo_tom


1 Answers

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;
like image 102
Frédéric Hamidi Avatar answered Nov 19 '22 13:11

Frédéric Hamidi