0

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?

2
  • 1
    You can't. You had one shot at getting the window created and you passed it up. The process itself will have to call AllocConsole(). Commented Jan 29, 2014 at 15:29
  • 1
    thanks for reply. If i can't then how do i implement this kind of functionality. I want that, there should be two button SHOW and HIDE, that will show and hide console App window created by CreateProcess. For this i am currently holding PROCESS_INFORMATION.. Commented Jan 30, 2014 at 4:18

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you friend... I have used this method to get Window Handle HWND. But when i use this HWND to show "mspaint.exe" window in WINDOWS 7 it come up with 3 windows on taskbar, first one is mspaint.exe which does not respond to any click on it, second is GDI+ window which is blank having titled with GDI+ and third is totally blank and does not have any title which too does not respond.. please give any reliable solution....
1

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.