开发者

How to get rid of the console window

开发者 https://www.devze.com 2023-04-06 21:53 出处:网络
I have tried to make a simple MessageBox using this code: #include <windows.h> int main() { MessageBox(NULL, \"Hello\", \"Message Box\", MB_OKCANCEL);

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.


  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).


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消