// 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 ¸Þ½ÃÁö 󸮱â