找到项目里的 $(projectDir)/proj.win32/main.cpp

宏定义里声明如下:

#define USE_WIN32_CONSOLE

函数修改如下:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // 这里是为了通过 bat 文件控制 Win32 游戏窗口大小
    int w = 1600;
    int h = 960;
    LPWSTR *szArgList;
    int argCount;
    szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);
    for(int i = 0; i < argCount; i++)
    {
        wchar_t* ext = L"WinSize";
        if (wcsstr(szArgList[i], ext))
        {
            w = _wtoi(szArgList[i+1]);
            h = _wtoi(szArgList[i+2]);
            break;
        }
    }
    LocalFree(szArgList);

// alloc一个console
#ifdef USE_WIN32_CONSOLE
    AllocConsole();
    freopen("CONIN$","r",stdin);
    freopen("CONOUT$","w",stdout);
    freopen("CONOUT$","r",stderr);
#endif

    // create the application instance
    AppDelegate app;
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setViewName("zombie");
    eglView->setFrameSize(w, h);
    int ret = CCApplication::sharedApplication()->run();

// 释放 console
#ifdef USE_WIN32_CONSOLE
    fclose(stderr);   
    fclose(stdout);   
    fclose(stdin);
    FreeConsole();
#endif

    return ret;
}