SFML community forums

Help => Window => Topic started by: David on April 27, 2011, 11:55:37 pm

Title: That annoying little window
Post by: David on April 27, 2011, 11:55:37 pm
I just started using SFML a few days ago :shock:

Whenever I run the code in Code::Blocks, the little CP-like window (I forgot what it's called) pops up along with the window that displays the images :evil:

How do you get rid of this window by code :?:
Title: That annoying little window
Post by: cooldog99 on April 28, 2011, 01:03:19 am
You don't need code to remove the console window :)

Project -> Properties -> Build Type -> it SHOULD say Console application, change it to Gui Application.
Make sure to set it to same on Debug AND release (on left) or whichever you prefer :D

Note: May require you to restart codeblocks, sometimes it does for me.

Hope this helps.
Title: That annoying little window
Post by: Mjonir on April 28, 2011, 01:10:10 am
On that subject, does anyone know if it's possible to do the opposite, i.e. forcing the console to appear in GUI Application (through code)?

It would be really nice for me if it was possible to control that through code (even an ugly piece) so that I could avoid making 2 different versions of my program and control that with a bool :P
Title: That annoying little window
Post by: cooldog99 on April 28, 2011, 01:25:10 am
Quote from: "Mjonir"
On that subject, does anyone know if it's possible to do the opposite, i.e. forcing the console to appear in GUI Application (through code)?

It would be really nice for me if it was possible to control that through code (even an ugly piece) so that I could avoid making 2 different versions of my program and control that with a bool :P


Why not just have a Console application? ;)

Otherwise you'll have to use some winAPI functions to call the console window, I forget exactly how as I hate using Windows.h heh.

Don't forget you can have multiple build targets in codeblocks (or other IDE's)
Title: That annoying little window
Post by: Mjonir on April 28, 2011, 01:31:39 am
My project is aimed at both scripters (who really need the console) and their end-users (who don't need/want to see the console). So at the moment I do have multiple build targets, but I'd be force to release two different versions of my program, one with the console and one without. If I could control that in the application itself, I could only give only one build and control that in the configuration file. It's not an absolute need, but it'd be neater if it's easy enough to control.

I'll have a look at Windows.h then. I hope it wouldn't break portability too much to do it this way though :?
Title: That annoying little window
Post by: David on April 28, 2011, 01:55:46 am
Quote from: "cooldog99"
You don't need code to remove the console window :)

Project -> Properties -> Build Type -> it SHOULD say Console application, change it to Gui Application.
Make sure to set it to same on Debug AND release (on left) or whichever you prefer :D

Note: May require you to restart codeblocks, sometimes it does for me.

Hope this helps.


Wow, jeez, I comPLETELY forgot about the GUI application option :shock:

Thanks a bunch  :D
Title: That annoying little window
Post by: Fred_FS on April 28, 2011, 02:21:03 am
Quote from: "Mjonir"
My project is aimed at both scripters (who really need the console) and their end-users (who don't need/want to see the console). So at the moment I do have multiple build targets, but I'd be force to release two different versions of my program, one with the console and one without. If I could control that in the application itself, I could only give only one build and control that in the configuration file. It's not an absolute need, but it'd be neater if it's easy enough to control.

I'll have a look at Windows.h then. I hope it wouldn't break portability too much to do it this way though :?

It is probably not as easy as you wish. Once you have created a new console-window you  have for example to redirect the standard input and output streams to this window.
It is possible and described here (http://dslweb.nwnexus.com/~ast/dload/guicon.htm), but it is rather complicated.

But I have an easy suggestion for you. Just create a console-application and if you don't want to show the console window, use
Code: [Select]

ShowWindow(GetConsoleWindow(), SW_HIDE);

to hide it(Further information (http://msdn.microsoft.com/en-us/library/ms633548%28VS.85%29.aspx)).

I think hiding an existing console is easier than creating a new one ;).
Title: That annoying little window
Post by: David on April 28, 2011, 02:45:30 am
Quote from: "Fred_FS"
Quote from: "Mjonir"
My project is aimed at both scripters (who really need the console) and their end-users (who don't need/want to see the console). So at the moment I do have multiple build targets, but I'd be force to release two different versions of my program, one with the console and one without. If I could control that in the application itself, I could only give only one build and control that in the configuration file. It's not an absolute need, but it'd be neater if it's easy enough to control.

I'll have a look at Windows.h then. I hope it wouldn't break portability too much to do it this way though :?

It is probably not as easy as you wish. Once you have created a new console-window you  have for example to redirect the standard input and output streams to this window.
It is possible and described here (http://dslweb.nwnexus.com/~ast/dload/guicon.htm), but it is rather complicated.

But I have an easy suggestion for you. Just create a console-application and if you don't want to show the console window, use
Code: [Select]

ShowWindow(GetConsoleWindow(), SW_HIDE);

to hide it(Further information (http://msdn.microsoft.com/en-us/library/ms633548%28VS.85%29.aspx)).

I think hiding an existing console is easier than creating a new one ;).


So would
Code: [Select]
ShowWindow(GetConsoleWindow(), SW_SHOW); also work?
Title: That annoying little window
Post by: Fred_FS on April 28, 2011, 11:24:19 am
As I mentioned in my last post, this would not work. At least not, if you're running a "Gui Application".
A window that does not exist will not be shown ;).

If you're using a console application, you can make your console visible again by using your code.
Title: That annoying little window
Post by: eglomer on August 09, 2011, 12:37:09 pm
If you need the console window but you don't want to show it always, you can use this code to show/hide it:

Code: [Select]
#include <windows.h>

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
class ConsoleWindow{
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
private:
HWND CONSOLE;

public:
ConsoleWindow(void);
void HideConsoleWindow (void);
void ShowConsoleWindow (void);
};


//----------------------------------------------------------------------------------------------------
ConsoleWindow::ConsoleWindow (void){
//----------------------------------------------------------------------------------------------------
SetConsoleTitle("- Console Window -");
sf::Sleep(1);
this->CONSOLE = FindWindow(NULL, "- Console Window -");
}

//----------------------------------------------------------------------------------------------------
void ConsoleWindow::HideConsoleWindow (void){
//----------------------------------------------------------------------------------------------------
ShowWindow(this->CONSOLE, SW_HIDE);
}

//----------------------------------------------------------------------------------------------------
void ConsoleWindow::ShowConsoleWindow (void){
//----------------------------------------------------------------------------------------------------
ShowWindow(this->CONSOLE, SW_SHOW);
}