16,473
社区成员
发帖
与我相关
我的任务
分享
BOOL CWaterSurveyApp::InitInstance()
{
AfxGetModuleState()->m_dwVersion = 0x0601;//使应用程序支持Dao3.6
//设置BCG的资源
CFileFind find;
static CString strt;
strt = CWsOperator::GetAppDir();
if(find.FindFile(CWsOperator::GetAppDir()+"\\BCGCBProRes*.dll"))
{
find.FindNextFile();
CString strResFile = find.GetFilePath();
m_hResourceModule = ::LoadLibrary(strResFile);
if ( m_hResourceModule != NULL )
{
BCGCBProSetResourceHandle(m_hResourceModule);
}
}
SmSetVisibleGeometrySize(327670000); //最大可见对象点数
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
globalData.SetDPIAware ();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
//注册信息
SetRegistryKey(gProducerRegister.strRegistryKey);
m_pSplashThread = (CSplashThread*) AfxBeginThread(RUNTIME_CLASS(CSplashThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
if (m_pSplashThread == NULL)
{
AfxMessageBox(_T("Failed to create splash screen"), MB_OK | MB_ICONSTOP);
return FALSE;
}
ASSERT(m_pSplashThread->IsKindOf(RUNTIME_CLASS(CSplashThread)));
DWORD code = -1;
//tBitmapToUse(const CString& sFilename);
CString strStartPicture = CWsOperator::GetAppDir() + _T("setup.bmp");
if(CSmToolkit::IsFileExisted(strStartPicture))//by shiww,have setup.bmp file,2006.5.30
{
m_pSplashThread->SetBitmapToUse(strStartPicture);
}
m_pSplashThread->ResumeThread();
short sYear = CSmToolkit::GetYear(); //当前时间的年值
short sMonth = CSmToolkit::GetMonth(); //当前时间的月值
short sDay = CSmToolkit::GetDay(); //当前时间的日值
if(sYear>2011
|| (sYear==2011 && sMonth>11) )
{
AfxMessageBox("本软件只能在2010年11月30日前使用.\r\n您已经过了试用期.\r\n如您需要继续使用软件,请与北京超图联系.");
m_pSplashThread->ExitInstance(); //退出
return FALSE;
}
else if( sYear==2010 && sMonth==11 && 30-sDay<=5)
{
CString strRemain;
strRemain.Format("本软件只能在2010年11月30日前使用.\r\n您离试用期结束还有%d天.",30-sDay);
AfxMessageBox(strRemain);
}
ReadSystemPara();
/*//
m_nNPolygonEdgeCount = GetProfileInt(gProducerRegister.strSystemPara, _T("NPolygonEdgeCount"), m_nNPolygonEdgeCount);
CString str = GetProfileString(gProducerRegister.strSystemPara, _T("GridRowSpace"));
if (!str.IsEmpty())
m_dGridRowSpace = _tcstod(str, NULL);
str = GetProfileString(gProducerRegister.strSystemPara, _T("GridColSpace"));
if (!str.IsEmpty())
m_dGridColSpace = _tcstod(str, NULL);
///////////////////////////////////////////////////////////////////////
//加载插件
LoadPlgIn();
int i = 0;
CSvPlugIn *pSvPlugIn = NULL;
for (; i < m_dPlugInfile.GetSize(); i++)
{
CREATEPLGIN CreatePlgIn =
(CREATEPLGIN)GetProcAddress((HINSTANCE)m_dPlugInfile.GetAt(i), _T("CreatePlugIn"));
if(CreatePlgIn != NULL)
{
pSvPlugIn = (CSvPlugIn *)CreatePlgIn();
if(pSvPlugIn != NULL)
{
m_dSvPlgIn.Add((DWORD)pSvPlugIn);
}
}
pSvPlugIn = NULL;
}
*/
//{{add by houpg, check whether commanding parameter files is exist
CString strAppPath = CWsOperator::GetAppDir()+"paras";//added by shiww,2006.4.30
CString strParaPath =CSmToolkit::GetTempPath();
strParaPath=strParaPath.Mid(0,strParaPath.GetLength()-1);
m_svPara.m_strParaPath = strParaPath;
//暂时先测试一下,by shiww,2006.5.22
//ADO 初始化
CAdoDataBase *pAdodatabase=new CAdoDataBase;// by shiww,没必要删除,m_svPara析构时会删除。
pAdodatabase->m_bShowError=FALSE;
TCHAR filepath[MAX_PATH];
GetModuleFileName(AfxGetApp()->m_hInstance,filepath, MAX_PATH-1);
CString strPath = CWsOperator::ExtractFilePath(filepath);
if (!pAdodatabase->ConnectMDB(strPath + _T("\\para\\para.mdb"), _T("")))
return FALSE;
m_svPara.SetAdoDatabase(pAdodatabase);
CSvToolkit::GetParaFileFromDB(pAdodatabase,m_svPara.m_strParaPath);
if(!m_svPara.LayerToLayerGroup())//出错处理
{
pAdodatabase->Close();
delete pAdodatabase;
pAdodatabase=NULL;
//m_pSplashThread->SetMessage(WM_COMMAND,WM_CLOSE,0);
GetExitCodeThread(m_pSplashThread, &code);
ExitProcess(code);
return FALSE;
}
gSysEnvironment = m_svPara.m_SysEvn;
//参数读取之后,MainFrame创建之前将其转移到上下文中,解决多个dll间无法共享静态变量问题
POSITION pos = m_svPara.m_mapVarients.GetStartPosition();
CString strKey;
CString strValue;
while (NULL != pos)
{
m_svPara.m_mapVarients.GetNextAssoc(pos, strKey, strValue);
InstanceContext->SetVarient(strKey, strValue);
}
// 获得实体描述
m_mapEntityIDtoDescription.RemoveAll();
CAdoRecordset *pRS = pAdodatabase->Query(_T("select ClassID, Description from Entity"), SMADO::adOpenForwardOnly);
if (pRS != NULL && !pRS->IsEmpty())
{
pRS->MoveFirst();
while (!pRS->IsEOF())
{
COleVariant var;
pRS->GetFieldValue(_T("ClassID"), var);
long nID = var.lVal;
pRS->GetFieldValue(_T("Description"), var);
m_mapEntityIDtoDescription.SetAt(nID, CString(var.bstrVal));
pRS->MoveNext();
}
}
pAdodatabase->ReleaseRecordset(pRS);
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
SetRegistryBase (_T("Settings"));
// Initialize all Managers for usage. They are automatically constructed
// if not yet present
InitContextMenuManager();
InitKeyboardManager();
// TODO: Remove this if you don't want extended tooltips:
// InitTooltipManager();
// CBCGPToolTipParams params;
// params.m_bVislManagerTheme = TRUE;
// theApp.GetTooltipManager ()->SetTooltipParams (
// BCGP_TOOLTIP_TYPE_ALL,
// RUNTIME_CLASS (CBCGPToolTipCtrl),
// ¶ms);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CWaterSurveyDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CWaterSurveyView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))//运行到此就报错
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->UpdateWindow();
///////////////////////
EnableShellOpen();
RegisterShellFileTypes();
// The main window has been initialized, so show and update it.
// pMainFrame->ShowWindow(m_nCmdShow);
m_pSplashThread->HideSplash();
return TRUE;
}