Is there a command that hides the dos window while the program executes??

Dani AI

Generated

Brief expert summary and practical options (adds to , , and ):

Runtime hide vs "no console" at build time — two different answers already in the thread solve different problems. Hiding the console at runtime (the ShowWindow/GetConsoleWindow approach noted by ) simply makes the already-created console invisible; it still exists for the process and can briefly appear or be visible in Task Manager. The GetConsoleWindow API is guarded by version macros, so it will only be declared if the Windows-target macros are set before pulling in headers. See the GetConsoleWindow reference and the guidance on the Windows header version macros. (learn.microsoft.com)

If the goal is "no console ever appears" (no brief flash), use a non-console build instead of hiding: set the program subsystem to Windows (MSVC linker) or use the compiler/linker option that produces a GUI EXE (for MinGW/GCC the documented choice is -mwindows). That prevents the OS from creating a console window at process start. Hiding after creation cannot always avoid the startup flash. See ShowWindow behavior and the -mwindows/subsystem approach. (learn.microsoft.com)

For launching child processes without visible consoles, prefer the process-creation flags (for example, CREATE_NO_WINDOW) or use ShellExecute/ShellExecuteEx for GUI targets rather than system("start ..."), which invokes cmd. The process-creation flags let a child run without a visible console window. (learn.microsoft.com)

Concrete troubleshooting tips for the Dev‑C++ / Code::Blocks / MinGW scenario seen in the thread:

  • Define the target macro before any Windows header or add it as a project compiler define (for example -D_WIN32_WINNT=0x0501) to avoid "undeclared" symbols and reduce redefinition noise; 0x0500 maps to Windows 2000, 0x0501 to XP — pick the level that matches the minimum OS you support.
  • To avoid the flash entirely, change the project type to "GUI" or add the subsystem/linker flag instead of hiding at runtime.
  • If headers are too old or the symbol is still missing, update the SDK/MinGW distribution.

Relevant references: GetConsoleWindow documentation, Using the Windows Headers, ShowWindow reference, process-creation flags, and the GCC/MinGW -mwindows option. (learn.microsoft.com)

Recommended Answers

All 15 Replies

Not long before did a similar thread arise. If you want to hide a window then you should use WIN32 rather than console as far as I know.

int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
}

I saw the functionn GetConsoleWindow() in MSDN but I am unable to use it in both the compilers I have ( Dev C++ & Code::Blocks ) Please Help

I saw the functionn GetConsoleWindow() in MSDN but I am unable to use it in both the compilers I have ( Dev C++ & Code::Blocks ) Please Help

You need to ... #define _WIN32_WINNT 0x0500 // ... or higher

Now I get this,

||=== Hide, Debug ===|
F:\Programs\VC\Hide\main.cpp|2|warning: "_WIN32_WINNT" redefined|
D:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\windef.h|20|warning: this is the location of the previous definition|
F:\Programs\VC\Hide\main.cpp||In function `int main()':|
F:\Programs\VC\Hide\main.cpp|7|error: `GetConsoleWindow' undeclared (first use this function)|
F:\Programs\VC\Hide\main.cpp|7|error: (Each undeclared identifier is reported only once for each function it appears in.)|
||=== Build finished: 2 errors, 2 warnings ===|

Add I do not know why I have to define _WIN32_WINNT, please do explain that too.

Define _WIN32_WINNT before you #include <windows.h> As to the reason why you need it, see Using Windows Headers

Great! No error No warning. The only problem was to search for the hidden window in task manager. Works great!

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <wincon.h>
int main()
{

    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
    system ( "start firefox www.daniweb.com" ) ;
    Sleep ( 2000 ) ;
    ShowWindow(hWnd, 1 ) ;
    return 0 ;
}

I am working with Windows XP so should not I use 0x501?

alright I get most of that except the "sleep" syntax. Is that telling the computer to delay 2000 ms (2 seconds) before continuing the program?

ehh, what the hell ? for some reason my post is before yours, even though i was answering yours :S

I am using Dev C++ and the command isn't being recognized....

Should I be running Mcro. Visual Studio to run "Sleep" or is there a directive that I haven't included yet?

Member Avatar for Member #46692

I use Dev, sleep should work as long as you have the #include <windows.h> and have a capital 'S' in Sleep(3000);

Yep I needed to include that directive. Thanks

ehh, what the hell ? for some reason my post is before yours, even though i was answering yours :S

Happens to me sometimes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.