如何在C語言中隱藏預設的DOS視窗(Windows下)?看這個問題問的人比較多,而網上的答案不盡人意,就自己寫個,放變大家!
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello world!"<<endl;
return 0;
}
方法一:
在你的控制台程式前加入
#ifdef _MSC_VER
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#endif
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout<<"Hello world!"<<endl;
::MessageBox(NULL , "" , "" , 0);
//暫停程式,就可以在工作管理員看這個我們的程式是運行了!
return 0;
}
方法二:
建立Win32工程,自己改成WinMain介面
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout<<"Hello world!"<<endl;
::MessageBox(NULL , "" , "" , 0);
//暫停程式,就可以在工作管理員看這個我們的程式是運行了!
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
main();
return 0;
}
作者:syx
本系列文章是作者學習心得筆記,歡迎轉載,請註明原文地址,如有疑問,可以通過 278250658@qq.com 聯絡作者本人。