C语言 如何隐藏DOS窗口

如何在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 联系作者本人。




原文地址:https://www.cnblogs.com/syxchina/p/2197274.html