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 g开发者_如何学JAVAet rid of this console window?
Yes, compile for the "windows" subsystem. Here are instructions for performing this task on multiple IDEs.
- Don't use Dev-C++; use a decent IDE instead.
- 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).
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);
}
精彩评论