|
// ENRIT.cpp : 定义应用程序的类动作。
|
//
|
|
#include "stdafx.h"
|
#include "afxwinappex.h"
|
#include "afxdialogex.h"
|
#include "ENRIT.h"
|
#include "MainFrm.h"
|
|
#include "ENRITDoc.h"
|
#include "ENRITView.h"
|
|
#include <gdiplus.h>
|
using namespace Gdiplus;
|
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#endif
|
|
|
#pragma comment(lib, "DbgHelp.lib")
|
|
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) {
|
//RCutProject_DmpFile.dmp
|
|
char szFileName[MAX_PATH];
|
struct stat buffer;
|
if (stat("D:\\Temp", &buffer) != 0)
|
{
|
CreateDirectory(_T("D:\\Temp"), NULL);
|
}
|
|
if (stat("D:\\Temp\\Log", &buffer) != 0)
|
{
|
CreateDirectory(_T("D:\\Temp\\Log"), NULL);
|
}
|
|
CString file_path;
|
file_path.Format(_T("D:\\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();
|
}
|
|
snprintf(szFileName, MAX_PATH, "D:\\Temp\\RCutProject_DmpFile.dmp");
|
|
AfxMessageBox(_T("system failure!!!"));
|
|
// ?孙冼遂
|
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, 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;
|
}
|
|
// CENRITApp
|
|
BEGIN_MESSAGE_MAP(CENRITApp, CWinApp)
|
ON_COMMAND(ID_APP_ABOUT, &CENRITApp::OnAppAbout)
|
// 基于标准文件的文件命令。
|
ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
|
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
|
END_MESSAGE_MAP()
|
|
|
// CENRITApp 生成
|
|
CENRITApp::CENRITApp()
|
{
|
// TODO: 将下面的应用程序ID字符串替换为固有ID字符串(建议)。
|
// 字符串的格式: CompanyName.ProductName.SubProduct.VersionInformation
|
SetAppID(_T("ENRIT.AppID.NoVersion"));
|
|
m_bCreateBase = FALSE;
|
m_bCreateLog = FALSE;
|
m_hMutex = NULL;
|
}
|
|
// 唯一的CENRITApp个体。
|
|
CENRITApp theApp;
|
|
|
// CENRITApp 初始化
|
|
BOOL CENRITApp::InitInstance()
|
{
|
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
|
CWinApp::InitInstance();
|
|
m_hMutex = ::CreateMutex(NULL,FALSE, _T("MutexRCutInspector"));
|
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;
|
}
|
}
|
|
if (!AfxSocketInit())
|
{
|
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
|
return FALSE;
|
}
|
|
// 初始化OLE库。
|
if (!AfxOleInit())
|
{
|
AfxMessageBox(IDP_OLE_INIT_FAILED);
|
return FALSE;
|
}
|
|
AfxEnableControlContainer();
|
|
EnableTaskbarInteraction(FALSE);
|
|
// 要使用RichEdit控制,必须有AfxInitRichEdit2()。
|
// AfxInitRichEdit2();
|
|
// 标准初始化
|
// 如果想在不使用这些功能的情况下缩小最终可执行文件的大小
|
// 下面不需要的特定初始化
|
// 你必须去除例行动作。
|
// 更改保存该设置的注册表键。
|
// TODO: 将该字符串与公司名称或组织名称相同
|
// 应该修改成适当的内容。
|
SetRegistryKey(_T("本地应用程序向导中生成的应用程序"));
|
LoadStdProfileSettings(4); // 加载标准INI文件选项,包括MRU。
|
|
if (NULL != g_pBase)
|
{
|
m_bCreateBase = TRUE;
|
}
|
|
if (NULL != g_pLog)
|
{
|
m_bCreateLog = TRUE;
|
//g_pLog->SetPath(_T("C:\\RCutProject\\log"));
|
}
|
|
if (NULL != g_pLang)
|
{
|
m_bCreateLang = TRUE;
|
}
|
|
// 注册应用程序的文档模板。
|
// 文档模板是文档、框架窗口和视图之间的连接。
|
CSingleDocTemplate* pDocTemplate;
|
pDocTemplate = new CSingleDocTemplate(
|
IDR_MAINFRAME,
|
RUNTIME_CLASS(CENRITDoc),
|
RUNTIME_CLASS(CMainFrame), // 主要SDI框架窗口。
|
RUNTIME_CLASS(CENRITView));
|
if (!pDocTemplate)
|
return FALSE;
|
AddDocTemplate(pDocTemplate);
|
|
// 分析标准外壳命令、DDE和打开文件的命令行。
|
CCommandLineInfo cmdInfo;
|
ParseCommandLine(cmdInfo);
|
|
// 在命令行中删除指定的命令。
|
// 如果应用程序以/RegServer、/Register、/Unregserver或/Unregister启动,则返回FALSE。
|
if (!ProcessShellCommand(cmdInfo))
|
return FALSE;
|
|
GdiplusStartupInput gdiplusStartupInput;
|
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
|
|
// 只有一个窗口初始化,显示并更新。
|
m_pMainWnd->ShowWindow(SW_SHOW);
|
m_pMainWnd->UpdateWindow();
|
// 只有在有后缀时才调用DragAcceptFiles。
|
// 在SDI的应用程序中,ProcessShellCommand之后应该发生这样的调用。
|
|
CMainFrame* pMain = static_cast<CMainFrame*>(AfxGetMainWnd());
|
//pMain->SetDoc(static_cast<CAlignInspectionDoc*>(pMain->GetActiveDocument()));
|
pMain->SetView(static_cast<CENRITView*>(pMain->GetActiveView()));
|
|
m_bCreateLog = TRUE;
|
|
return TRUE;
|
}
|
|
int CENRITApp::ExitInstance()
|
{
|
m_bCreateBase = FALSE;
|
m_bCreateLog = FALSE;
|
m_bCreateLang = FALSE;
|
|
CloseHandle(m_hMutex);
|
|
//TODO: 处理添加的资源。
|
AfxOleTerm(FALSE);
|
|
return CWinApp::ExitInstance();
|
}
|
|
// CENRITApp消息处理器
|
|
|
// 用于应用程序信息的CAboutDlg对话框。
|
|
class CAboutDlg : public CDialogEx
|
{
|
public:
|
CAboutDlg();
|
|
// 对话框数据。
|
enum { IDD = IDD_ABOUTBOX };
|
|
protected:
|
virtual void DoDataExchange(CDataExchange* pDX);
|
|
// 实现。
|
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 CENRITApp::OnAppAbout()
|
{
|
CAboutDlg aboutDlg;
|
aboutDlg.DoModal();
|
}
|
|
// CENRITApp消息处理器
|