如何骑车的控制箱的GUI程序由MinGW + Code :: Block编译 [英] How to get ride of console box of a GUI program compile by MinGW + Code::Block
问题描述
当我使用命令行测试在MinGW + MSys中编译一个简单的Win32 GUI程序并运行:
When I test compile a simple Win32 GUI program in MinGW+MSys with command line and run it:
$ g ++ main.cpp -o app -std = c ++ 0x
$ g++ main.cpp -o app -std=c++0x
$ ./app
只显示一个对话框。但把这个程序代码:: Block IDE并编译它,它一个黑色的控制台与对话框。在链接选项中添加-mwindows无效。
only a dialog box shows. But put this program into Code::Block IDE and compile it, it aways plus a black console box with the dialog. Add -mwindows in link options no effect.
main.cpp
#include <windows.h>
int WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
MessageBox(0,"Hello, Windows","MinGW Test Program",MB_OK);
return 0;
}
推荐答案
并且在项目设置中有一个选项没有控制台窗口。
Put it in a project, and in the project settings there's an option to not have a console window.
如果你不能在项目中使用它,调用 ShowWindow(GetConsoleWindow(),SW_HIDE);
会使它在屏幕上闪烁,然后消失。请注意,在包含windows.h以访问<$ c $之前,您必须 #define _WIN32_WINNT
为 0x0500
c> GetConsoleWindow()。
If you can't be bothered to have it in a project, a call to ShowWindow (GetConsoleWindow(), SW_HIDE);
will make it flash on the screen and then disappear. Note that you must #define _WIN32_WINNT
as 0x0500
or greater before including windows.h to have access to GetConsoleWindow()
. I'll come back in a bit with a specific location to disable it.
//hide console window at start
#define _WIN32_WINNT 0x0501 //this is for XP
#include <windows.h>
int main()
{
ShowWindow (GetConsoleWindow(), SW_HIDE);
//rest of program here
}
编辑:
找到它,这里是如何没有控制台窗口:
Found it, here's how to not have a console window:
- 在CodeBlocks菜单上单击项目。
- 点击属性。
- 点击第二个标签,即构建目标。
- 在右侧, GUI应用程序。
- 重建项目。
- Click Project on the CodeBlocks menu.
- Click Properties.
- Click the second tab, Build Targets.
- On the right, where it says Type: Console application, change it to GUI application.
- Rebuild the project.
这篇关于如何骑车的控制箱的GUI程序由MinGW + Code :: Block编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!