void CSaveOptionPage::RegFileType(LPCTSTR pszType) { POSITION posTmpl = AfxGetApp()->GetFirstDocTemplatePosition(); if(posTmpl != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmpl); CString strFileTypeId; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId)) { CString strTemp; LONG lSize = _MAX_PATH * 2; LONG lResult = AfxRegQueryValue(HKEY_CLASSES_ROOT, pszType, strTemp.GetBuffer(lSize), &lSize); strTemp.ReleaseBuffer(); if(strTemp.Compare(strFileTypeId) != 0) { AfxRegSetValue( HKEY_CLASSES_ROOT, pszType, REG_SZ, strFileTypeId, lstrlen(strFileTypeId) * sizeof(TCHAR)); AfxGetApp()->WriteProfileString(_T("Settings"), pszType, strTemp); } } } }
void CSaveOptionPage::UnRegFileType(LPCTSTR pszType) { POSITION posTmpl = AfxGetApp()->GetFirstDocTemplatePosition(); if(posTmpl != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmpl); CString strFileTypeId; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId)) { CString strTemp = AfxGetApp()->GetProfileString(_T("Settings"), pszType); if(strTemp.Compare(strFileTypeId) != 0) { AfxRegSetValue( HKEY_CLASSES_ROOT, pszType, REG_SZ, strTemp, lstrlen(strTemp) * sizeof(TCHAR)); } } } }
BOOL CFamiTrackerApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. InitCommonControls(); #ifdef SUPPORT_TRANSLATIONS LoadLocalization(); #endif CWinApp::InitInstance(); TRACE("App: InitInstance\n"); if (!AfxOleInit()) { TRACE("OLE initialization failed\n"); } // 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 // 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(_T("")); LoadStdProfileSettings(MAX_RECENT_FILES); // Load standard INI file options (including MRU) // Load program settings m_pSettings = CSettings::GetObject(); m_pSettings->LoadSettings(); // Parse command line for standard shell commands, DDE, file open + some custom ones CFTCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (CheckSingleInstance(cmdInfo)) return FALSE; //who: added by Derek Andrews <*****@*****.**> //why: Load all custom exporter plugins on startup. TCHAR pathToPlugins[MAX_PATH]; GetModuleFileName(NULL, pathToPlugins, MAX_PATH); PathRemoveFileSpec(pathToPlugins); PathAppend(pathToPlugins, _T("\\Plugins")); m_customExporters = new CCustomExporters( pathToPlugins ); // Load custom accelerator m_pAccel = new CAccelerator(); m_pAccel->LoadShortcuts(m_pSettings); m_pAccel->Setup(); // Create the MIDI interface m_pMIDI = new CMIDI(); // Create sound generator m_pSoundGenerator = new CSoundGen(); // Create channel map m_pChannelMap = new CChannelMap(); // Start sound generator thread, initially suspended if (!m_pSoundGenerator->CreateThread(CREATE_SUSPENDED)) { // If failed, restore and save default settings m_pSettings->DefaultSettings(); m_pSettings->SaveSettings(); // Show message and quit AfxMessageBox(IDS_START_ERROR, MB_ICONERROR); return FALSE; } // Check if the application is themed CheckAppThemed(); // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views CDocTemplate0CC* pDocTemplate = new CDocTemplate0CC( // // // IDR_MAINFRAME, RUNTIME_CLASS(CFamiTrackerDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CFamiTrackerView)); if (!pDocTemplate) return FALSE; if (m_pDocManager == NULL) // // // m_pDocManager = new CDocManager0CC { }; m_pDocManager->AddDocTemplate(pDocTemplate); // Work-around to enable file type registration in windows vista/7 if (IsWindowsVistaOrGreater()) { // // // HKEY HKCU; long res_reg = ::RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Classes"), &HKCU); if(res_reg == ERROR_SUCCESS) RegOverridePredefKey(HKEY_CLASSES_ROOT, HKCU); } // Enable DDE Execute open EnableShellOpen(); // Skip this if in wip/beta mode #if !defined(WIP) && !defined(_DEBUG) // Add shell options RegisterShellFileTypes(); // // // static const LPCTSTR FILE_ASSOC_NAME = _T("0CC-FamiTracker Module"); AfxRegSetValue(HKEY_CLASSES_ROOT, "0CCFamiTracker.Document", REG_SZ, FILE_ASSOC_NAME, lstrlen(FILE_ASSOC_NAME) * sizeof(TCHAR)); // Add an option to play files CString strPathName, strTemp, strFileTypeId; AfxGetModuleShortFileName(AfxGetInstanceHandle(), strPathName); CString strOpenCommandLine = strPathName; strOpenCommandLine += _T(" /play \"%1\""); if (pDocTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty()) { strTemp.Format(_T("%s\\shell\\play\\%s"), (LPCTSTR)strFileTypeId, _T("command")); AfxRegSetValue(HKEY_CLASSES_ROOT, strTemp, REG_SZ, strOpenCommandLine, lstrlen(strOpenCommandLine) * sizeof(TCHAR)); } #endif // Handle command line export if (cmdInfo.m_bExport) { CCommandLineExport exporter; exporter.CommandLineExport(cmdInfo.m_strFileName, cmdInfo.m_strExportFile, cmdInfo.m_strExportLogFile, cmdInfo.m_strExportDPCMFile); ExitProcess(0); } // Dispatch commands specified on the command line. Will return FALSE if // app was launched with /RegServer, /Register, /Unregserver or /Unregister. if (!ProcessShellCommand(cmdInfo)) { if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { // Also clear settings from registry when unregistering m_pSettings->DeleteSettings(); } return FALSE; } // Move root key back to default if (IsWindowsVistaOrGreater()) { // // // ::RegOverridePredefKey(HKEY_CLASSES_ROOT, NULL); } // The one and only window has been initialized, so show and update it m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); // call DragAcceptFiles only if there's a suffix // In an SDI app, this should occur after ProcessShellCommand // Enable drag/drop open m_pMainWnd->DragAcceptFiles(); // Initialize the sound interface, also resumes the thread if (!m_pSoundGenerator->InitializeSound(m_pMainWnd->m_hWnd)) { // If failed, restore and save default settings m_pSettings->DefaultSettings(); m_pSettings->SaveSettings(); // Quit program AfxMessageBox(IDS_START_ERROR, MB_ICONERROR); return FALSE; } // Initialize midi unit m_pMIDI->Init(); if (cmdInfo.m_bPlay) theApp.StartPlayer(MODE_PLAY); #ifdef EXPORT_TEST if (cmdInfo.m_bVerifyExport) { m_bExportTesting = true; VerifyExport(cmdInfo.m_strVerifyFile); } else { // Append menu option m_pMainWnd->GetMenu()->GetSubMenu(2)->AppendMenu(MF_SEPARATOR); m_pMainWnd->GetMenu()->GetSubMenu(2)->AppendMenu(MF_STRING, ID_MODULE_TEST_EXPORT, _T("Test exporter")); } #endif // Save the main window handle RegisterSingleInstance(); #ifndef _DEBUG m_pMainWnd->GetMenu()->GetSubMenu(4)->RemoveMenu(ID_MODULE_CHANNELS, MF_BYCOMMAND); // // // #endif if (m_pSettings->General.bCheckVersion) // // // CheckNewVersion(true); // Initialization is done TRACE("App: InitInstance done\n"); return TRUE; }
BOOL CStkUIApp::InitInstance() { // 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. AfxSocketInit( ); AfxOleInit(); // 程序只能启动一个实例 m_pMutex = CreateMutex(NULL, FALSE, _T("TsKing")); if (m_pMutex != NULL) { if (GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(m_pMutex); m_pMutex = NULL; return FALSE; } } GetVersionNumber(); AfxGetProfile().LoadProfile( ); ::SetCurrentDirectory( AfxGetProfile().GetWorkDirectory() ); AfxGetSView().Load( AfxGetProfile().GetSViewFile() ); // 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( szRegKeyCompany ); AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Path", AfxGetProfile().GetWorkDirectory() ); AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Version", AfxGetProfile().GetVersion() ); // change profile ( INI file ) BOOL bEnable = AfxEnableMemoryTracking(FALSE); if( m_pszProfileName ) free((void*)m_pszProfileName); m_pszProfileName = _tcsdup(AfxGetProfile().GetWorkDirectory()+m_pszExeName+".ini"); AfxEnableMemoryTracking(bEnable); LoadStdProfileSettings(64); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. // Enable DDE Execute open EnableShellOpen(); AfxUnregisterShellFileTypes(); // AfxRegisterShellFileTypes(FALSE); // Empty Temp Directory { CNetDatabase netdb; if (netdb.SetRootPath(AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB)) netdb.EmptyTempDirectory(); } AfxSetDB(&AfxGetNetDB()); //*/ // Load Data char szErr[1024]; if (!AfxInitializeDB(szErr, sizeof(szErr))) { AfxMessageBox(szErr, MB_OK | MB_ICONINFORMATION); return FALSE; } // 初始化 AfxGetStockContainer().Load(&AfxGetDB(), NULL, NULL); // 读取证券信息,代码表、财务、除权等 AfxGetDomainContainer().Load(AfxGetProfile().GetDomainFile()); // 读取板块 AfxGetGroupContainer().Load(AfxGetProfile().GetGroupFile()); // 读取自选板块 // 分析标准外壳命令、DDE、打开文件操作的命令行 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); #ifdef _TSK_MAINFRAME // 注册应用程序的文档模板。文档模板 // 将用作文档、框架窗口和视图之间的连接 CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CStaticDoc), RUNTIME_CLASS(CMainFrame), // 主 SDI 框架窗口 RUNTIME_CLASS(CSListView)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // 调度在命令行中指定的命令。如果 // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; #else // Create MainFrame and Static Doc and child frames and static views CStaticDoc* pStaticDoc = CStaticDoc::OpenDocumentFile(NULL); if (pStaticDoc == NULL) { AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION); return FALSE; } pStaticDoc->m_bAutoDelete = FALSE; CString strAppTitle; strAppTitle.LoadString(AFX_IDS_APP_TITLE); pStaticDoc->SetTitle(strAppTitle); SetStaticDoc(pStaticDoc); // Create MainFrame CMainFrame* pMainFrame = CMainFrame::CreateNewFrame(); if (pMainFrame == NULL) { AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION); delete pStaticDoc; SetStaticDoc(NULL); return FALSE; } SetMainWnd(pMainFrame); #endif // 股票行情接收 AfxGetStkReceiver().CreateReceiver(m_pMainWnd); AfxGetStkReceiver().NetEngineSetAutoReport(FALSE); /* Show Startup Window CStartupDlg startup; CBitmap bmp; bmp.LoadBitmap(IDB_DLGLEFTLOGO); startup.SetBitmap((HBITMAP)bmp.GetSafeHandle()); startup.SetLoadProgramFunc(LoadProgram); if (IDOK != startup.DoModal()) { pMainFrame->SendMessage(WM_CLOSE); return FALSE; } //*/ /* Show Splash Window CSplashDlg splash; CBitmap bmp; bmp.LoadBitmap(IDB_SPLASH); splash.SetBitmap(HBITMAP(bmp.GetSafeHandle())); splash.Create(NULL, 0, AfxGetSView().GetU(), AfxGetSView().GetS(), AfxGetVersionString(), FALSE, 0, STKLIB_MAX_PROGRESS); splash.ShowWindow(SW_SHOW); splash.UpdateWindow(); LoadProgram(splash.GetSafeHwnd(), 0, STKLIB_MAX_PROGRESS); splash.DestroyWindow(); //*/ // ////////////////////////////////////////////////////////////// // Open Simulation Strategy if (GetFirstStrategyPosition() == NULL) { if (OpenLastOpenedStrategy() == 0) OpenDefaultStrategy(); } //if (!AfxGetStaticDoc()->GetViewIfExist(RUNTIME_CLASS(CSListView))) // AfxGetStaticDoc()->ShowStaticView(RUNTIME_CLASS(CSListView), TRUE); //AfxSwitchToStaticView(RUNTIME_CLASS(CSListView)); AfxGetProfile().SetCurrentStock(STKLIB_CODE_SZZS, FALSE); ((CMainFrame*)m_pMainWnd)->m_SearchBox.InitStocks( TRUE, TRUE, TRUE ); ((CMainFrame*)m_pMainWnd)->m_SearchBox.SetCurrentWindowText(); //*////////////////////////////////////////////////////////////// // Dispatch commands specified on the command line if( CCommandLineInfo::AppUnregister == cmdInfo.m_nShellCommand ) { AfxUnregisterShellFileTypes(); if (!cmdInfo.m_bRunEmbedded) AfxMessageBox(AFX_IDP_UNREG_DONE, MB_OK | MB_ICONINFORMATION); if (m_pCmdInfo == NULL) { m_pCmdInfo = new CCommandLineInfo; m_pCmdInfo->m_nShellCommand = CCommandLineInfo::AppUnregister; } return FALSE; } // Dispatch commands specified on the command line if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen) { OpenStrategyFile(cmdInfo.m_strFileName); AfxSwitchToStaticView(RUNTIME_CLASS(CSimuView)); } // 启动通视接收系统,不显示选择接收系统对话框 //AfxGetStkReceiver().EngineBeginWorking(FALSE); // The one and only window has been initialized, so show and update it. // Load Last WindowPlacement WINDOWPLACEMENT wp; if (AfxGetProfile().GetWindowPlacement(&wp)) m_pMainWnd->SetWindowPlacement(&wp); else m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED); // Enable drag/drop open //m_pMainWnd->DragAcceptFiles(); // Check New Version m_pMainWnd->SetTimer(TIMER_AUTOUPDATE, 5000, NULL); return TRUE; }