user95644
user95644

Reputation:

Disable showing console window

Where I can disable in Microsoft-Visual-C++ showing console window?

Upvotes: 14

Views: 30678

Answers (6)

John
John

Reputation: 39

In my case (vs2022 c++) all i did was:

Modify

int main() {

to

int WinMain() {

and

Properties > Linker > System change SubSystem to Windows

Upvotes: 4

Underdisc
Underdisc

Reputation: 321

For CMake users.

add_executable(${exeName} WIN32)

You'll need to use WinMain instead of main for the entry point symbol.

Upvotes: 1

MaKiPL
MaKiPL

Reputation: 1200

You can disable console by manipulating pre-compiled EXE subsystem- this way you don't need any change in code as you are working on final product- negative aspect is that you would need to do this every time you recompile the project. You can do it via HEX editor or use free CFF Explorer.

  1. Open EXE via CFF Explorer
  2. Go to Nt Headers>Optional Header
  3. Navigate over Subsystem and on the right side click on Windows Console and select Windows GUI.
  4. Save file, console will no longer appear

You can do binary comparison and find the exact location in raw PE header, then maybe do some automation after-compile in VS

Upvotes: 3

Mike de Klerk
Mike de Klerk

Reputation: 12338

You could hide it right on startup. I do not know whether this will cause flicker:

HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );

Upvotes: 3

Indy9000
Indy9000

Reputation: 8881

In your console application, goto

Properties > Linker > System 

change SubSystem to Windows

and in your code replace

int _tmain(int argc, _TCHAR* argv[])

with

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

and add

#include <windows.h>

This should avoid showing a console window in your console application.

Upvotes: 28

Matthew Iselin
Matthew Iselin

Reputation: 10670

Your question is quite ambiguous, so I'm going to try and answer how I interpreted it... If you don't want a console window, try using a different subsystem. Specifically, you probably want the Windows or Native subsystem rather than the Console subsystem.

Upvotes: 0

Related Questions