Hide Command Prompt in Console Application
-
I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?
-
I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?
1. Why do you need to do this? 2. If you don't want a window, you could use a Win32 application instead of a console application, where you could hide the window before it's shown. 3. Alternatively, if you're launching this console app from another app, then you could use CreateProcess[^], passing CREATE_NO_WINDOW[^] for the
dwCreationFlags
parameter.“Follow your bliss.” – Joseph Campbell
-
1. Why do you need to do this? 2. If you don't want a window, you could use a Win32 application instead of a console application, where you could hide the window before it's shown. 3. Alternatively, if you're launching this console app from another app, then you could use CreateProcess[^], passing CREATE_NO_WINDOW[^] for the
dwCreationFlags
parameter.“Follow your bliss.” – Joseph Campbell
-
I am not launching my application from another application. I have to create console application because in some cases I have to show command prompt and in some cases not to show.
In which case, start your console application from a Win32 app and show or hide it as needed. You cannot 'hide' a console application from within itself before the console window is shown - or none that I know of. This is because the window creation is not done by the console program, but the system does it. The advice given in previous reply can be used if you decide to use a Win32 program for this.
“Follow your bliss.” – Joseph Campbell
-
I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?
-
you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it. hope this will solve your problem.
lisunlin wrote:
you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it.
I don't see how could this solve the given problem.
“Follow your bliss.” – Joseph Campbell
-
I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?
Stop compiling your application as a console application, but as a windows application (Remove "console" from the compiler and linker options)
-
lisunlin wrote:
you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it.
I don't see how could this solve the given problem.
“Follow your bliss.” – Joseph Campbell