954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Hiding dos window

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

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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.

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 
Is there a command that hides the dos window while the program executes??

You might be looking for something like this http://www.codeproject.com/KB/winsdk/runsilent.aspx

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 
int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 
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

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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.

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

Define _WIN32_WINNT before you #include <windows.h>

As to the reason why you need it, see Using Windows Headers

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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?

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

Yep :P

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

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?

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

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?

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Yep I needed to include that directive. Thanks

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 
ehh, what the hell ? for some reason my post is before yours, even though i was answering yours :S


Happens to me sometimes.

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You