📄 configtool.cpp
字号:
if(strFile.Exists()){ m_arstrUserToolPaths.Add(strFolder); if(m_strUserToolsDir.IsEmpty()){ m_strUserToolsDir=strFolder; } } } } }}BOOL CConfigToolApp::OnIdle(LONG lCount) { if(lCount==0) { CMainFrame *pMain=CConfigTool::GetMain(); if(pMain){ // During startup the main window will be the splash screen CDC *pDC=pMain->GetDC(); CFont *pOldFont=pDC->SelectObject(pMain->m_wndStatusBar.GetFont()); pDC->SelectObject(pOldFont); pMain->ReleaseDC(pDC); } } return CWinApp::OnIdle(lCount);}BOOL CConfigToolApp::PreTranslateMessage(MSG* pMsg){ // CG: The following lines were added by the Splash Screen component. if (CSplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg);}BOOL CAboutDlg::OnInitDialog() { CString strVersion; strVersion.Format(_T("%s %s"),_T(__DATE__),_T(__TIME__)); SetDlgItemText(IDC_STATIC_DATETIME,strVersion); CDialog::OnInitDialog(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}bool CConfigToolApp::Launch(const CString & strFileName,const CString &strViewer){ bool rc=false; if(!strViewer.IsEmpty())//use custom editor { CString strCmdline(strViewer); TCHAR *pszCmdLine=strCmdline.GetBuffer(strCmdline.GetLength()); GetShortPathName(pszCmdLine,pszCmdLine,strCmdline.GetLength()); strCmdline.ReleaseBuffer(); strCmdline+=_TCHAR(' '); strCmdline+=strFileName; PROCESS_INFORMATION pi; STARTUPINFO si; si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpReserved2 = NULL; si.cbReserved2 = 0; si.lpDesktop = NULL; si.dwFlags = 0; si.lpTitle=NULL; if(CreateProcess( NULL, // app name //strCmdline.GetBuffer(strCmdline.GetLength()), // command line strCmdline.GetBuffer(strCmdline.GetLength()), // command line NULL, // process security NULL, // thread security TRUE, // inherit handles 0, NULL, // environment NULL, // current dir &si, // startup info &pi)){ CloseHandle(pi.hProcess); CloseHandle(pi.hThread); rc=true; } else { CUtils::MessageBoxF(_T("Failed to invoke %s.\n"),strCmdline); } strCmdline.ReleaseBuffer(); } else {// Use association TCHAR szExe[MAX_PATH]; HINSTANCE h=FindExecutable(strFileName,_T("."),szExe); if(int(h)<=32){ CString str; switch(int(h)){ case 0: str=_T("The system is out of memory or resources.");break; case 31: str=_T("There is no association for the specified file type.");break; case ERROR_FILE_NOT_FOUND: str=_T("The specified file was not found.");break; case ERROR_PATH_NOT_FOUND: str=_T("The specified path was not found.");break; case ERROR_BAD_FORMAT: str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).");break; default: break; } CUtils::MessageBoxF(_T("Failed to open document %s.\r\n%s"),strFileName,str); } else { SHELLEXECUTEINFO sei = {sizeof(sei), 0, AfxGetMainWnd()->GetSafeHwnd(), _T("open"), strFileName, NULL, NULL, SW_SHOWNORMAL, AfxGetInstanceHandle( )}; sei.hInstApp=0; HINSTANCE hInst=ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),_T("open"), strFileName, NULL, _T("."), 0)/*ShellExecuteEx(&sei)*/; if(int(hInst)<=32/*sei.hInstApp==0*/) { CString str; switch(int(hInst)) { case 0 : str=_T("The operating system is out of memory or resources. ");break; case ERROR_FILE_NOT_FOUND : str=_T("The specified file was not found. ");break; case ERROR_PATH_NOT_FOUND : str=_T("The specified path was not found. ");break; case ERROR_BAD_FORMAT : str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). ");break; case SE_ERR_ACCESSDENIED : str=_T("The operating system denied access to the specified file. ");break; case SE_ERR_ASSOCINCOMPLETE : str=_T("The filename association is incomplete or invalid. ");break; case SE_ERR_DDEBUSY : str=_T("The DDE transaction could not be completed because other DDE transactions were being processed. ");break; case SE_ERR_DDEFAIL : str=_T("The DDE transaction failed. ");break; case SE_ERR_DDETIMEOUT : str=_T("The DDE transaction could not be completed because the request timed out. ");break; case SE_ERR_DLLNOTFOUND : str=_T("The specified dynamic-link library was not found. ");break; //case SE_ERR_FNF : str=_T("The specified file was not found. ");break; case SE_ERR_NOASSOC : str=_T("There is no application associated with the given filename extension. ");break; case SE_ERR_OOM : str=_T("There was not enough memory to complete the operation. ");break; //case SE_ERR_PNF : str=_T("The specified path was not found. ");break; case SE_ERR_SHARE : str=_T("A sharing violation occurred. ");break; default: str=_T("An unexpected error occurred");break; } CUtils::MessageBoxF(_T("Failed to open document %s using %s.\r\n%s"),strFileName,szExe,str); } else { rc=true; } } } return rc;}/*void CConfigToolApp::AddToRecentFileList(LPCTSTR lpszPathName) {const CFileName strDir=CFileName(lpszPathName).Head();if(strDir.IsDir()){CWinApp::AddToRecentFileList(strDir);}}*/int CConfigToolApp::GetRepositoryRegistryClues(CStringArray &arstr,LPCTSTR pszPrefix){ // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths arstr.RemoveAll(); CRegKeyEx k1(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"),KEY_READ); CString strKey; for(int i=0;k1.QueryKey(i,strKey);i++){ if(0==strKey.Find(pszPrefix)){ CRegKeyEx k2((HKEY)k1,strKey,KEY_READ); CFileName strDir; if(k2.QueryValue(_T("Path"),strDir) && strDir.IsDir()){ arstr.Add(strDir); } } } return arstr.GetSize();}void CAboutDlg::OnLButtonDblClk(UINT nFlags, CPoint point) { UNUSED_ALWAYS(point); UNUSED_ALWAYS(nFlags);}//const char CConfigToolApp::s_profileFlags[] = _T("flags");LPCTSTR CConfigToolApp::s_profileMax = _T("max");LPCTSTR CConfigToolApp::s_profileTool = _T("tool");LPCTSTR CConfigToolApp::s_profileStatus = _T("status");LPCTSTR CConfigToolApp::s_profileRect = _T("Rect");void CConfigToolApp::SaveWindowPlacement(CWnd *pWnd, const CString &strKey){ // Our position CString strText; WINDOWPLACEMENT wndpl; wndpl.length = sizeof(WINDOWPLACEMENT); // gets current window position and // iconized/maximized status pWnd->GetWindowPlacement(&wndpl); strText.Format(_T("%04d %04d %04d %04d"), wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top, wndpl.rcNormalPosition.right, wndpl.rcNormalPosition.bottom); if(!pWnd->IsWindowVisible()){ wndpl.showCmd=SW_HIDE; } WriteProfileInt (strKey,_T("Show"), wndpl.showCmd); WriteProfileString(strKey,s_profileRect, strText);}BOOL CConfigToolApp::RestoreWindowPlacement(CWnd *pWnd,const CString &strKey,const CRect &rcDefault){ // Set the windows according to registry settings CString strText; WINDOWPLACEMENT wndpl; CRect rect; strText = GetProfileString(strKey,s_profileRect); if (!strText.IsEmpty()) { rect.left = _ttoi((LPCTSTR ) strText); rect.top = _ttoi((LPCTSTR ) strText + 5); rect.right = _ttoi((LPCTSTR ) strText + 10); rect.bottom = _ttoi((LPCTSTR ) strText + 15); } else { rect = rcDefault; } CRect rcMax; SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0); if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){ rect=rcDefault; } wndpl.length = sizeof(WINDOWPLACEMENT); wndpl.showCmd = GetProfileInt(strKey,_T("Show"),SW_SHOWNA); wndpl.flags = 0; wndpl.ptMinPosition = CPoint(0, 0); wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER)); wndpl.rcNormalPosition = rect; // sets window's position and iconized/maximized status return pWnd->SetWindowPlacement(&wndpl);}void CConfigToolApp::LoadFont(const CString & strKey, LOGFONT & lf){ lf.lfHeight =(LONG)GetProfileInt(strKey,_T("Height"),0); if(0==lf.lfHeight){ CFont font; font.Attach(HFONT(GetStockObject(DEFAULT_GUI_FONT))); font.GetLogFont(&lf); } else { lf.lfWidth =(LONG)GetProfileInt(strKey,_T("Width"),0); lf.lfEscapement =(LONG)GetProfileInt(strKey,_T("Escapement"),0); lf.lfOrientation =(LONG)GetProfileInt(strKey,_T("Orientation"),0); lf.lfWeight =(LONG)GetProfileInt(strKey,_T("Weight"),0); lf.lfItalic =(BYTE)GetProfileInt(strKey,_T("Italic"),0); lf.lfUnderline =(BYTE)GetProfileInt(strKey,_T("Underline"),0); lf.lfStrikeOut =(BYTE)GetProfileInt(strKey,_T("StrikeOut"),0); lf.lfCharSet =(BYTE)GetProfileInt(strKey,_T("CharSet"),0); lf.lfOutPrecision =(BYTE)GetProfileInt(strKey,_T("OutPrecision"),0); lf.lfClipPrecision =(BYTE)GetProfileInt(strKey,_T("ClipPrecision"),0); lf.lfQuality =(BYTE)GetProfileInt(strKey,_T("Quality"),0); lf.lfPitchAndFamily =(BYTE)GetProfileInt(strKey,_T("PitchAndFamily"),0); CString strFaceName =GetProfileString(strKey,_T("FaceName"),_T("")); if(strFaceName.GetLength()<=31){ _tcscpy(lf.lfFaceName,strFaceName); } else { lf.lfFaceName[0]=_TCHAR('\0'); } }}void CConfigToolApp::SaveFont(const CString & strKey, const LOGFONT & lf){ WriteProfileInt(strKey,_T("Height"), (int)lf.lfHeight); WriteProfileInt(strKey,_T("Width"), (int)lf.lfWidth); WriteProfileInt(strKey,_T("Escapement"), (int)lf.lfEscapement); WriteProfileInt(strKey,_T("Orientation"), (int)lf.lfOrientation); WriteProfileInt(strKey,_T("Weight"), (int)lf.lfWeight); WriteProfileInt(strKey,_T("Italic"), (int)lf.lfItalic); WriteProfileInt(strKey,_T("Underline"), (int)lf.lfUnderline); WriteProfileInt(strKey,_T("StrikeOut"), (int)lf.lfStrikeOut); WriteProfileInt(strKey,_T("CharSet"), (int)lf.lfCharSet); WriteProfileInt(strKey,_T("OutPrecision"), (int)lf.lfOutPrecision); WriteProfileInt(strKey,_T("ClipPrecision"), (int)lf.lfClipPrecision); WriteProfileInt(strKey,_T("Quality"), (int)lf.lfQuality); WriteProfileInt(strKey,_T("PitchAndFamily"),(int)lf.lfPitchAndFamily); WriteProfileString(strKey,_T("FaceName"), lf.lfFaceName);}CEditView *CConfigTool::m_pEditView=NULL;COutputView *CConfigTool::m_pOutputView=NULL;CControlView *CConfigTool::m_pControlView=NULL;CCellView *CConfigTool::m_pCellView=NULL;CDescView *CConfigTool::m_pDescView=NULL;CPropertiesView *CConfigTool::m_pPropertiesView=NULL;CRulesView *CConfigTool::m_pRulesView=NULL;CConfigToolDoc *CConfigTool::m_pConfigToolDoc=NULL;CMainFrame *CConfigTool::m_pMain=NULL;CMLTView *CConfigTool::m_pMLTView=NULL;CControlView *CConfigTool::GetControlView() { return m_pControlView; }COutputView *CConfigTool::GetOutputView() { return m_pOutputView; }CCellView *CConfigTool::GetCellView() { return m_pCellView; }CDescView *CConfigTool::GetDescView() { return m_pDescView; }CPropertiesView *CConfigTool::GetPropertiesView() { return m_pPropertiesView; }CRulesView *CConfigTool::GetRulesView() { return m_pRulesView; }CMLTView *CConfigTool::GetMLTView() { return m_pMLTView; }void CConfigTool::SetDocument(CConfigToolDoc *pDoc) {m_pConfigToolDoc=pDoc; }void CConfigTool::SetMain(CMainFrame * pMain) { m_pMain=pMain; }void CConfigTool::SetControlView(CControlView *pControlView) {m_pControlView=pControlView; }void CConfigTool::SetOutputView(COutputView *pOutputView) {m_pOutputView=pOutputView; }void CConfigTool::SetCellView(CCellView *pCellView) {m_pCellView=pCellView; }void CConfigTool::SetDescView(CDescView *pDescView) {m_pDescView=pDescView; }void CConfigTool::SetMLTView(CMLTView *pMLTView) {m_pMLTView=pMLTView; }void CConfigTool::SetPropertiesView(CPropertiesView *pPropertiesView) {m_pPropertiesView=pPropertiesView; }void CConfigTool::SetRulesView(CRulesView *pRulesView) {m_pRulesView=pRulesView; }CMainFrame *CConfigTool::GetMain(){ CWnd *pWnd=AfxGetMainWnd(); return (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)))?(CMainFrame*)pWnd:NULL;}int CConfigTool::Log(LPCTSTR pszFormat, ...){ va_list marker; va_start (marker, pszFormat); for(int nLength=100;nLength;) { TCHAR *buf=new TCHAR[1+nLength]; int n=_vsntprintf(buf, nLength, pszFormat, marker ); if(-1==n){ nLength*=2; // NT behavior } else if (n<nLength){ CWnd *pMain=CConfigTool::GetMain(); if(pMain){ // During startup the main window will be the splash screen COutputView *pView=CConfigTool::GetOutputView(); if(pView){ pView->AddText(buf); pView->AddText(_T("\r\n")); } } ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=buf; ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=_T("\r\n"); nLength=0; // trigger exit from loop } else { nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length } delete [] buf; } va_end (marker); return 0;}void CConfigTool::DismissSplash(){ CSplashWnd::EnableSplashScreen(FALSE);}CString CConfigToolApp::GetInstallVersionKey (){ CString strKey = _T("SOFTWARE\\Red Hat\\eCos"); CString strVersionKey = _T(""); CString rc = _T(""); TCHAR pszBuffer [MAX_PATH + 1]; HKEY hKey; // get the greatest eCos version subkey if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) { DWORD dwIndex = 0; while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) { if (strVersionKey.Compare (pszBuffer) < 0) { strVersionKey = pszBuffer; } } RegCloseKey (hKey); } return strKey + _T("\\") + strVersionKey;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -