// EdgeInspector_App.cpp : 览侩 橇肺弊伐俊 措茄 努贰胶 悼累阑 沥狼钦聪促. // #include "stdafx.h" #include "afxwinappex.h" #include "afxdialogex.h" #include "EdgeInspector_App.h" #include "MainFrm.h" #include "EdgeInspector_AppDoc.h" #include "EdgeInspector_AppView.h" #include #include #ifdef _DEBUG #define new DEBUG_NEW #endif #pragma comment(lib, "DbgHelp.lib") BOOL g_bUse_SaveAllDMP = FALSE; LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) { // 太阋冼遂伲 char szFileName[MAX_PATH]; struct stat buffer; if (stat("D:\\Inspection\\Temp", &buffer) != 0) { CreateDirectory(_T("D:\\Inspection\\Temp"), NULL); } if (stat("D:\\Inspection\\Temp\\Log", &buffer) != 0) { CreateDirectory(_T("D:\\Inspection\\Temp\\Log"), NULL); } CString file_path; file_path.Format(_T("D:\\Inspection\\Temp\\Log\\%s.csv"), g_pBase->m_strLoadingDay); CFile file_module; CFileException exception; file_module.Open(file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &exception); if (exception.m_cause == CFileException::none) { if (file_module.SeekToEnd() == 0L) { CString defect_title; defect_title.Format(_T("Date,GlassID,Path,Versions\r\n")); file_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR)); } SYSTEMTIME st; GetLocalTime(&st); CString strTime; strTime.Format(_T("%02d:%02d:%02d"), st.wHour, st.wMinute, st.wSecond); CString strVersions = L""; TCHAR szAppFile[MAX_PATH] = { 0 }; ::GetModuleFileName(NULL, szAppFile, MAX_PATH); HANDLE hAppFile = CreateFile(szAppFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hAppFile != INVALID_HANDLE_VALUE) { FILETIME fileTime_Create; FILETIME fileTime_LastAccess; FILETIME fileTime_LastWrite; if (!GetFileTime(hAppFile, &fileTime_Create, &fileTime_LastAccess, &fileTime_LastWrite)) { CloseHandle(hAppFile); } else { FILETIME fileTime_Local; FileTimeToLocalFileTime(&fileTime_LastWrite, &fileTime_Local); FileTimeToSystemTime(&fileTime_Local, &st); strVersions.Format(L"%04d/%02d/%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); CloseHandle(hAppFile); } } CString strData; strData.Format(_T("%s,%s,%s,%s\r\n"), strTime, g_pBase->m_strHPanelID, szAppFile, strVersions); file_module.Write(strData, strData.GetLength() * sizeof(TCHAR)); file_module.Close(); } AfxMessageBox(_T("system failure!!!")); snprintf(szFileName, MAX_PATH, "D:\\Inspection\\Temp\\EdgeInspector_DmpFile.dmp"); // ?孙冼遂 HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION dumpInfo; dumpInfo.ExceptionPointers = pExceptionInfo; dumpInfo.ThreadId = GetCurrentThreadId(); dumpInfo.ClientPointers = TRUE; // ?忑dump冼遂 BOOL success = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, g_bUse_SaveAllDMP ? MiniDumpWithFullMemory : MiniDumpFilterMemory, &dumpInfo, NULL, NULL); CloseHandle(hFile); if (!success) { std::cerr << "Failed to write dump file." << std::endl; } else { std::cerr << "Dump file written to " << szFileName << std::endl; } } else { std::cerr << "Failed to create dump file." << std::endl; } return EXCEPTION_EXECUTE_HANDLER; } // CEdgeInspector_App BEGIN_MESSAGE_MAP(CEdgeInspector_App, CWinAppEx) ON_COMMAND(ID_APP_ABOUT, &CEdgeInspector_App::OnAppAbout) // 钎霖 颇老阑 扁檬肺 窍绰 巩辑 疙飞涝聪促. ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen) // 钎霖 牢尖 汲沥 疙飞涝聪促. ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup) END_MESSAGE_MAP() // CEdgeInspector_App 积己 CEdgeInspector_App::CEdgeInspector_App() { SetUnhandledExceptionFilter(MyUnhandledExceptionFilter); m_bHiColorIcons = TRUE; // 促矫 矫累 包府磊 瘤盔 m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS; #ifdef _MANAGED // 览侩 橇肺弊伐阑 傍侩 攫绢 繁鸥烙 瘤盔阑 荤侩窍咯 呼靛茄 版快(/clr): // 1) 捞 眠啊 汲沥篮 促矫 矫累 包府磊 瘤盔捞 力措肺 累悼窍绰 单 鞘夸钦聪促. // 2) 橇肺璃飘俊辑 呼靛窍妨搁 System.Windows.Forms俊 措茄 曼炼甫 眠啊秦具 钦聪促. System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException); #endif // TODO: 酒贰 览侩 橇肺弊伐 ID 巩磊凯阑 绊蜡 ID 巩磊凯肺 官操绞矫坷(鼻厘). // 巩磊凯俊 措茄 辑侥: CompanyName.ProductName.SubProduct.VersionInformation SetAppID(_T("EdgeInspector_App.AppID.NoVersion")); // TODO: 咯扁俊 积己 内靛甫 眠啊钦聪促. // InitInstance俊 葛电 吝夸茄 檬扁拳 累诀阑 硅摹钦聪促. m_bCreateBase = FALSE; m_bCreateLog = FALSE; m_hMutex = NULL; } // 蜡老茄 CEdgeInspector_App 俺眉涝聪促. CEdgeInspector_App theApp; // CEdgeInspector_App 檬扁拳 BOOL CEdgeInspector_App::InitInstance() { // 览侩 橇肺弊伐 概聪其胶飘啊 ComCtl32.dll 滚傈 6 捞惑阑 荤侩窍咯 厚林倔 胶鸥老阑 // 荤侩窍档废 瘤沥窍绰 版快, Windows XP 惑俊辑 馆靛矫 InitCommonControlsEx()啊 鞘夸钦聪促. // InitCommonControlsEx()甫 荤侩窍瘤 臼栏搁 芒阑 父甸 荐 绝嚼聪促. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 览侩 橇肺弊伐俊辑 荤侩且 葛电 傍侩 牧飘费 努贰胶甫 器窃窍档废 // 捞 亲格阑 汲沥窍绞矫坷. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); m_hMutex = ::CreateMutex(NULL,FALSE, _T("MutexEdgeInspector_App")); if (m_hMutex != NULL) { if(::GetLastError() == ERROR_ALREADY_EXISTS) { AfxMessageBox(_T("The Program is already running. Exit this Program."), MB_OK | MB_ICONERROR); return FALSE; } } // OLE 扼捞宏矾府甫 檬扁拳钦聪促. if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); EnableTaskbarInteraction(FALSE); // RichEdit 牧飘费阑 荤侩窍妨搁 AfxInitRichEdit2()啊 乐绢具 钦聪促. // AfxInitRichEdit2(); // 钎霖 檬扁拳 // 捞甸 扁瓷阑 荤侩窍瘤 臼绊 弥辆 角青 颇老狼 农扁甫 临捞妨搁 // 酒贰俊辑 鞘夸 绝绰 漂沥 檬扁拳 // 风凭阑 力芭秦具 钦聪促. // 秦寸 汲沥捞 历厘等 饭瘤胶飘府 虐甫 函版窍绞矫坷. // TODO: 捞 巩磊凯阑 雀荤 肚绰 炼流狼 捞抚苞 鞍篮 // 利例茄 郴侩栏肺 荐沥秦具 钦聪促. SetRegistryKey(_T("肺拿 览侩 橇肺弊伐 付过荤俊辑 积己等 览侩 橇肺弊伐")); LoadStdProfileSettings(4); // MRU甫 器窃窍咯 钎霖 INI 颇老 可记阑 肺靛钦聪促. if (NULL != g_pBase) { m_bCreateBase = TRUE; } if (NULL != g_pLog) { m_bCreateLog = TRUE; } InitContextMenuManager(); InitKeyboardManager(); InitTooltipManager(); CMFCToolTipInfo ttParams; ttParams.m_bVislManagerTheme = TRUE; theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL, RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); // 览侩 橇肺弊伐狼 巩辑 袍敲复阑 殿废钦聪促. 巩辑 袍敲复篮 // 巩辑, 橇饭烙 芒 棺 轰 荤捞狼 楷搬 开且阑 钦聪促. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CEdgeInspector_AppDoc), RUNTIME_CLASS(CMainFrame), // 林 SDI 橇饭烙 芒涝聪促. RUNTIME_CLASS(CEdgeInspector_AppView)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // 钎霖 夹 疙飞, DDE, 颇老 凯扁俊 措茄 疙飞临阑 备巩 盒籍钦聪促. CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 疙飞临俊 瘤沥等 疙飞阑 叼胶菩摹钦聪促. // 览侩 橇肺弊伐捞 /RegServer, /Register, /Unregserver 肚绰 /Unregister肺 矫累等 版快 FALSE甫 馆券钦聪促. if (!ProcessShellCommand(cmdInfo)) return FALSE; // 芒 窍唱父 檬扁拳登菌栏骨肺 捞甫 钎矫窍绊 诀单捞飘钦聪促. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); // 立固荤啊 乐阑 版快俊父 DragAcceptFiles甫 龋免钦聪促. // SDI 览侩 橇肺弊伐俊辑绰 ProcessShellCommand 饶俊 捞矾茄 龋免捞 惯积秦具 钦聪促. CMainFrame* pMain = static_cast(AfxGetMainWnd()); //pMain->SetDoc(static_cast(pMain->GetActiveDocument())); pMain->SetView(static_cast(pMain->GetActiveView())); return TRUE; } int CEdgeInspector_App::ExitInstance() { m_bCreateBase = FALSE; m_bCreateLog = FALSE; CloseHandle(m_hMutex); //TODO: 眠啊茄 眠啊 府家胶甫 贸府钦聪促. AfxOleTerm(FALSE); return CWinAppEx::ExitInstance(); } // CEdgeInspector_App 皋矫瘤 贸府扁 // 览侩 橇肺弊伐 沥焊俊 荤侩登绰 CAboutDlg 措拳 惑磊涝聪促. class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 措拳 惑磊 单捞磐涝聪促. enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 瘤盔涝聪促. // 备泅涝聪促. protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // 措拳 惑磊甫 角青窍扁 困茄 览侩 橇肺弊伐 疙飞涝聪促. void CEdgeInspector_App::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } // CEdgeInspector_App 荤侩磊 瘤沥 肺靛/历厘 皋辑靛 void CEdgeInspector_App::PreLoadState() { BOOL bNameValid; CString strName; bNameValid = strName.LoadString(IDS_EDIT_MENU); ASSERT(bNameValid); GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT); } void CEdgeInspector_App::LoadCustomState() { } void CEdgeInspector_App::SaveCustomState() { } // CEdgeInspector_App 皋矫瘤 贸府扁