shubhendu mahajan
shubhendu mahajan

Reputation: 816

How to get rid of the console window

I have tried to make a simple MessageBox using this code:

#include <windows.h>

int main() {
  MessageBox(NULL, "Hello", "Message Box", MB_OKCANCEL);
}

But upon building this in the Dev-C++ IDE with the MinGW toolchain, I get a console window popping up behind the MessageBox.

Is there a way to get rid of this console window?

Upvotes: 2

Views: 2363

Answers (3)

gamner61
gamner61

Reputation: 1

Here you go

#include <Windows.h>

int main() {
HWND hwnd;
AllocConsole();
hwnd = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(hwnd, 0);
MessageBox(NULL, "Hello", "Message Box", MB_OKCANCEL);
ShowWindow(hwnd, 0);
}

Upvotes: 0

Andr&#233; Caron
Andr&#233; Caron

Reputation: 45239

Yes, compile for the "windows" subsystem. Here are instructions for performing this task on multiple IDEs.

Upvotes: 7

Cat Plus Plus
Cat Plus Plus

Reputation: 129754

  1. Don't use Dev-C++; use a decent IDE instead.
  2. Compile for the WINDOWS subsystem, instead of the CONSOLE one. Even braindead Dev-C++ should have option for that (the entry point should be called WinMain — see any introduction to Windows programming).

Upvotes: 1

Related Questions