Reputation: 401
I have a GUI in c++. The GUI used to start another independent console based application using CreateProcess
method. I am hiding these console apps by passing CREATE_NO_WINDOW
flag in CreateProcess
. Now I want to make it visible again. How do I do that?
Upvotes: 0
Views: 5788
Reputation: 21
You had one shot at getting the window created and you passed it up. Thats right but you can show or hide gui, after createProcess method.
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si,sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi);
si.wShowWindow = SW_SHOW;
si.dwFlags = STARTF_USESHOWWINDOW;
si.lpTitle ="my_process_console";
CreateProcess(null,"my.exe",null,null,false,CREATE_NEW__CONSOLE,null,null,&si,&pi);
I created process.Now I use find method and then I can show GUI.
HWND console_name =FindWindow(null,"my_process_console");
if(console_name){
ShowWindow(console_name,SW_SHOW);
}
Upvotes: 1
Reputation: 595320
Instead of using the CREATE_NO_WINDOW
flag, use the wShowWindow
member of the STARTUPINFO
struct instead. Set it to SW_HIDE
initially (and set the dwFlags
member to STARTF_USESHOWWINDOW
), then you can use ShowWindow()
to show/hide the console window when needed. To find the window that belongs to the new process, use EnumWindows()
and GetWindowThreadProcessId()
to find the window whose process/thread IDs match the IDs that CreateProcess()
returns in the PROCESS_INFORMATION
struct.
Upvotes: 1