简体   繁体   English

如何摆脱控制台 window

[英]How to get rid of the console window

I have tried to make a simple MessageBox using this code:我尝试使用以下代码制作一个简单的MessageBox

#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 .但是在使用 MinGW 工具链在 Dev-C++ IDE 中构建它时,我在MessageBox后面弹出了一个控制台 window 。

Is there a way to get rid of this console window?有没有办法摆脱这个控制台 window?

Yes, compile for the "windows" subsystem. 是的,编译“windows”子系统。 Here are instructions for performing this task on multiple IDEs . 以下是在多个IDE上执行此任务的说明

  1. Don't use Dev-C++; 不要使用Dev-C ++; use a decent IDE instead. 使用一个体面的IDE代替。
  2. Compile for the WINDOWS subsystem, instead of the CONSOLE one. 编译WINDOWS子系统,而不是CONSOLE子系统。 Even braindead Dev-C++ should have option for that (the entry point should be called WinMain — see any introduction to Windows programming). 即使是braindead Dev-C ++也应该有选择(入口点应该叫做WinMain - 请参阅Windows编程的任何介绍)。

Here you go给你 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM