Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the black window in C++ [duplicate]

Possible Duplicate:
Create an Application without a Window
Win32 programming hiding console window

How can I hide the console window that appears when I run my C++ program? The program doesn't output anything to stdout, and I don't need that black window to appear each time I run the program. I don't want it to be minimized I want it to be invisible. Any ideas?

like image 889
dsynkd Avatar asked Jan 20 '12 16:01

dsynkd


2 Answers

If you want to hide the console you can call FreeConsole on windows

#include <Windows.h>

int main()
{
    FreeConsole();
    //other stuff
}

As David mentioned this might flash for a brief second. If you don't want that you can create a windows service or a windows gui application and not create a window like below

#include <windows.h>

int WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    //do stuff here
    return 0;
}
like image 170
parapura rajkumar Avatar answered Oct 03 '22 19:10

parapura rajkumar


It sounds like the problem is that you are creating a console application. These come with a console by default. They either inherit the console of the process that called them, if it has one, or otherwise create a new console.

You should make your application target the GUI subsystem rather than the console subsystem. This doesn't mean that you have to show any GUI. It's perfectly reasonable and commonplace to make an application that targets the GUI subsytem but does not show any windows.

like image 37
David Heffernan Avatar answered Oct 03 '22 18:10

David Heffernan