axmol/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/main.cpp

74 lines
1.8 KiB
C++
Raw Normal View History

2014-03-11 16:52:06 +08:00
#include "main.h"
#include "AppDelegate.h"
#include "cocos2d.h"
#include "SimulatorWindow.h"
2014-03-19 09:50:06 +08:00
#include <shellapi.h>
2014-03-11 16:52:06 +08:00
USING_NS_CC;
// uncomment below line, open debug console
#define USE_WIN32_CONSOLE
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
2014-04-10 15:51:25 +08:00
LPWSTR *szArgList=nullptr;
int argCount=0;
2014-03-18 18:24:58 +08:00
2014-04-10 15:51:25 +08:00
szArgList = CommandLineToArgvW(GetCommandLine(),&argCount);
if (argCount >=2 )
{
int iLen = 2*wcslen(szArgList[1]);
char* chRtn = new char[iLen+1];
wcstombs(chRtn,szArgList[1],iLen+1);
extern std::string g_resourcePath;
g_resourcePath = chRtn;
delete [] chRtn;
}
LocalFree(szArgList);
2014-03-18 18:24:58 +08:00
2014-03-11 16:52:06 +08:00
#ifdef USE_WIN32_CONSOLE
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
#endif
// create the application instance
AppDelegate app;
2014-04-10 15:51:25 +08:00
createSimulator("HelloLua",960,640);
2014-03-11 16:52:06 +08:00
int ret = Application::getInstance()->run();
#ifdef USE_WIN32_CONSOLE
FreeConsole();
#endif
return ret;
}
std::string getCurAppPath(void)
{
2014-04-10 15:51:25 +08:00
TCHAR szAppDir[MAX_PATH]={0};
if (!GetModuleFileName(NULL,szAppDir,MAX_PATH))
return "";
int nEnd=0;
for (int i=0;szAppDir[i];i++)
{
if(szAppDir[i]=='\\')
nEnd = i;
}
szAppDir[nEnd] = 0;
int iLen = 2*wcslen(szAppDir);
char* chRtn = new char[iLen+1];
wcstombs(chRtn,szAppDir,iLen+1);
std::string strPath = chRtn;
delete [] chRtn;
chRtn=NULL;
char fuldir[MAX_PATH]={0};
_fullpath(fuldir,strPath.c_str(),MAX_PATH);
return fuldir;
2014-03-11 16:52:06 +08:00
}