加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx Win32下添加控制台输出

发布时间:2020-12-14 17:17:43 所属栏目:百科 来源:网络整理
导读:只需要在main函数里面添加一句代码,再重新编译运行就好 // uncomment below line,open debug console#define USE_WIN32_CONSOLEint WINAPI _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow){UNREFERENCED_PARAMETER(

只需要在main函数里面添加一句代码,再重新编译运行就好

// uncomment below line,open debug console
#define USE_WIN32_CONSOLE


int WINAPI _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine,int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
#ifdef USE_WIN32_CONSOLE
	AllocConsole();
	freopen("CONIN$","r",stdin);
	freopen("CONOUT$","w",stdout);
	freopen("CONOUT$",stderr);
#endif


	auto simulator = SimulatorWin::getInstance();
	int ret = simulator->run();


#ifdef USE_WIN32_CONSOLE
	FreeConsole();
#endif


	return ret;
}
其中起作用的就是这几句了
#ifdef USE_WIN32_CONSOLE
	AllocConsole();
	freopen("CONIN$",stderr);
#endif

#ifdef USE_WIN32_CONSOLE
	FreeConsole();
#endif

这个宏定义就是开关
// uncomment below line,open debug console
#define USE_WIN32_CONSOLE

当然,新版里面有一个SimulatorWin.cpp 文件,这个文件里面定义了一个宏

#define SIMULATOR_WITH_CONSOLE_AND_MENU 0

这个宏要是等于0,那么就不会显示控制台输出,只要将这个宏的值改为 0 以上的数,控制台就完美的显示出来了

将上面宏的值换成下面这个

#define SIMULATOR_WITH_CONSOLE_AND_MENU 1

因为在这个文件的 248 行有这么一个判断

#if (SIMULATOR_WITH_CONSOLE_AND_MENU > 0)
    // create console window
    if (_project.isShowConsole())
    {
        AllocConsole();
        _hwndConsole = GetConsoleWindow();
        if (_hwndConsole != NULL)
        {
            ShowWindow(_hwndConsole,SW_SHOW);
            BringWindowToTop(_hwndConsole);
            freopen("CONOUT$","wt",stdout);
            freopen("CONOUT$",stderr);

            HMENU hmenu = GetSystemMenu(_hwndConsole,FALSE);
            if (hmenu != NULL)
            {
                DeleteMenu(hmenu,SC_CLOSE,MF_BYCOMMAND);
            }
        }
    }
#endif

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读