Thread: Hiding the console window?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    31

    Hiding the console window?

    I wrote a short application that searches for a file. If it finds it, it will run it... if it doesn't, it will ask if you want to install it.

    The application is a console application. While it is searching, I would like to hide the console window. Is this possible?

    Note 1: I've tested it with Notepad.exe and it works, finding it and running it when I press any key...

    Note 2: I am using Visual C++ as my compiler.

    Thanks,

    Xeno
    Welcome to the funhouse, where strange mirrors reflect the faces of insanity.

  2. #2
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Minimize it? or don't show the bar in the staus bar?

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    31
    Sorry, I should have mentioned that... I would like to not show it at all but if that isn't an option, I'd like to minimize it and / or not show it in the taskbar.

    Thanks.
    Welcome to the funhouse, where strange mirrors reflect the faces of insanity.

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    In MSVC, create a new Win32 Application. Put your code inside WinMain. Simple, no window, nothing. If you want to alert the user of something, use MessageBox();

    This is what the main cpp would look like:
    Code:
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	MessageBox(NULL, "Hi", "I'm alerting you!", 0);
    
    	return 0;
    }

  5. #5
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    No, he wants to be using a console app, open a prog from within that, and then hide the console app window, right?

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You can use FreeConsole() & Alloc Console() to detach your apps from the console (It doent really work it you run it from a command prmopt though - only from double clicking the program).......

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "Woohoo...I am on the console!!" << endl;
    	Sleep(2000);
    	FreeConsole();
    	MessageBox(HWND_DESKTOP,
    		"Woohoo...I have killed the console!!","Sigh :(",
    		MB_OK | MB_ICONEXCLAMATION);
    	AllocConsole();
    	cout << "Woohoo...The console lives again!!" << endl;
    	Sleep(2000);
    	FreeConsole();
    	MessageBox(HWND_DESKTOP,
    		"Er....that's it!!","Bah!! :(",
    		MB_OK | MB_ICONEXCLAMATION);
    
    	return 0;
    }
    Once more though...if you are really concerned about your programs on-screen actions, then you should look to building a GUI application....a console isnt built to look nice on screen

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    31
    Thanks, I was reading about FreeConsole() on msdn.microsoft.com but wasn't sure how to implement it.

    I originally tried to make a Win32 app but kept getting all sorts of compile errors about unresolved external references in one of the include files... so I abandoned the idea.

    But... for some reason, I was able to create both the Console version and the Win32 version today... guess sleep is useful after all.

    Xeno
    Welcome to the funhouse, where strange mirrors reflect the faces of insanity.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Window opening with Console Window
    By carrotcake1029 in forum Windows Programming
    Replies: 2
    Last Post: 12-23-2008, 03:32 PM
  2. Console window in VC 2008
    By swgh in forum Tech Board
    Replies: 0
    Last Post: 06-05-2008, 03:13 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. maximize console window
    By detux in forum C Programming
    Replies: 1
    Last Post: 09-30-2006, 10:50 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM