Hello,
I have decided to make a timer program on my computer to limit the amount of time that I game. Anyways, I have it working fine with a small borderless window in the top left of the screen that ticks down and when it gets to 0 it sounds an alarm, turns red, and waits for me to click it. The problem is that the console window pops up and looks very out of place. Is there some kind of SDL or Windows function that will allow me to destroy that window yet still maintain all the functionality of my SDL window?

You can go into your project settings and make it a Win32 Windows application and that will hide the console window.

The issue is that it isn't a project. I tend to make my own projects because they are slightly smaller in size and easier to run. All I have is an executable in the same folder as a bunch of resources (images, sounds, headers). Is there any way to do this from within the .cpp so that the .exe hides the executable on its own?

Here is the folder (I just used the tree /f command):

ALARM.wav
BAD.png
FONT.ttf
GOOD.png
GUIGamingCounter.exe
ICON.bmp
ICON.ico
jpeg.dll
libpng12-0.dll
libtiff-3.dll
MINUTES.txt
Random.h
SDL_image.dll
zlib1.dll

Edited 5 Years Ago by Labdabeta: n/a

If you are using Windows it's pretty simple, but not exactly guaranteed to not "flash" a console window for a moment.

What sfuo meant is you can tell your compiler to not spawn the console window. It's a compiler switch.

Now, this is the "dirty" way...

#include <Windows.h>

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

For some reason it is telling me that GetConsoleWindow() was not declared in this scope, even though I included <windows.h>? I also tried changing <windows.h> to <Windows.h> with no success. Here are my headers:

#include <windows.h>
#include <fstream>
#include <sstream>
#include "SDL\SDL.h"
#include "SDL\SDL_image.h"
#include "SDL\SDL_ttf.h"
#include "SDL\SDL_mixer.h"
#include "Random.h"
#define WINDOW_WIDTH 200
#define WINDOW_HEIGHT 50
#define WINDOW_BPP 32

Any ideas?

Thanks, I was able to figure a way out:

SetConsoleTitle("||||||||||");
    Sleep(5);
    HWND CONSOLE=FindWindow(NULL, "||||||||||");
    ShowWindow(CONSOLE, SW_HIDE);

This works fine when run from Code::Blocks, but when run as a stand-alone executable the console doesn't go away?

Edited 5 Years Ago by Labdabeta: Testing failed

Sorry for the double post, but I hit another problem. When I ran the program from C::B the console disappeared, but now its waiting for me to "Hit any key to continue..." before I can build it again. But the console is gone, so how do I get it to end execution?

right click your taskbar and select "Task Manager", go to the "Processes" tab, and kill the process.

Really, you should find the compiler option to not create the console window--it will avoid trouble like that.

There is no process there, just Code::Blocks itself and my other programs, but not the process that I was testing. Also it still doesn't hide the console when I run the executable outside of Code::Blocks.

Okay, I used code blocks with the GCC compiler and this works for me:

#if       _WIN32_WINNT < 0x0500
  #undef  _WIN32_WINNT
  #define _WIN32_WINNT   0x0500
#endif

#include <windows.h>

int main()
{
    ShowWindow(GetConsoleWindow(),SW_HIDE);
    Sleep(5000);//Sleep so I can check the task manager for the process.
    return 0;
}

It works inside the editor and outside of it, despite the editor making you press any key.

You can, of course, show the window again at the end of the program.

My best advice to you is to use the right compiler switch to make the console window not appear at all.

This question has already been answered. Start a new discussion instead.