// LaiPuLaser.cpp : 定义应用程序的类行为。 // #include "stdafx.h" #include "afxwinappex.h" #include "afxdialogex.h" #include "LaiPuLaser.h" #include "MainFrm.h" #include "ChildFrm.h" #include "LaiPuLaserDoc.h" #include "LaiPuLaserView.h" #include "FontTypeMgr.h" #include "WorkCmdInvoker.h" #include "ModuleDeviceMgr.h" #include "ModuleDrawMgr.h" #include "AuthorityMgr.h" #include "Layer.h" #include "GlobalFunction.h" #include "ProgramLaserTuiHuo.h" #include "EncryptionMgr.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CLaiPuLaserApp BEGIN_MESSAGE_MAP(CLaiPuLaserApp, CWinAppEx) ON_COMMAND(ID_APP_ABOUT, &CLaiPuLaserApp::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() // CLaiPuLaserApp 构造 CLaiPuLaserApp::CLaiPuLaserApp() { EnableHtmlHelp(); 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 //为 CompanyName.ProductName.SubProduct.VersionInformation SetAppID(_T("LaiPuDrawing.AppID.NoVersion")); // 将所有重要的初始化放置在 InitInstance 中 } // 唯一的一个 CLaiPuLaserApp 对象 CLaiPuLaserApp theApp; // CLaiPuLaserApp 初始化 BOOL CLaiPuLaserApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } // 初始化 OLE 库 if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); EnableTaskbarInteraction(); // 使用 RichEdit 控件需要 AfxInitRichEdit2() // AfxInitRichEdit2(); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); #if 0 HANDLE hObject = ::CreateMutex(NULL,FALSE, _T("LaipuDrawing")); if(GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(hObject); AfxMessageBox(("程序不能重复运行,请在任务管理器中查看Laipu进程!")); return FALSE; } #endif LoadStdProfileSettings(10); // 加载标准 INI 文件选项(包括 MRU) InitContextMenuManager(); InitShellManager(); InitKeyboardManager(); InitTooltipManager(); CMFCToolTipInfo ttParams; ttParams.m_bVislManagerTheme = TRUE; theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); // 注册应用程序的文档模板。文档模板 // 将用作文档、框架窗口和视图之间的连接 CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate(IDR_LAIPU_LASER_MENU, RUNTIME_CLASS(CLaiPuLaserDoc), RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架 RUNTIME_CLASS(CLaiPuLaserView)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // 创建主 MDI 框架窗口 CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } m_pMainWnd = pMainFrame; // 仅当具有后缀时才调用 DragAcceptFiles // 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生 // 启用拖/放 m_pMainWnd->DragAcceptFiles(); // 分析标准 shell 命令、DDE、打开文件操作的命令行 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 启用“DDE 执行” EnableShellOpen(); RegisterShellFileTypes(TRUE); // 调度在命令行中指定的命令。如果 // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; // 主窗口已初始化,因此显示它并对其进行更新 #if 0 //pMainFrame->ShowWindow(m_nCmdShow); CChildFrame *pChild = (CChildFrame*)pMainFrame->GetActiveFrame(); pChild->ShowWindow(SW_SHOWMAXIMIZED);//默认最大化 pMainFrame->ShowWindow(SW_SHOWMAXIMIZED); pMainFrame->UpdateWindow(); #endif // 主窗口已初始化,因此显示它并对其进行更新 //pMainFrame->ShowWindow(m_nCmdShow); CChildFrame *pChild = (CChildFrame*)pMainFrame->GetActiveFrame(); pChild->ShowWindow(SW_SHOWMAXIMIZED);//默认最大化 //pMainFrame->ShowWindow(SW_SHOWMAXIMIZED); pMainFrame->UpdateWindow(); LaiPuAppInitialize(); return TRUE; } void CLaiPuLaserApp::LaiPuAppInitialize() { gAuthorityMgr->SetAuthority(_Authority_Factory);//以下步骤需要最高权限 //初始化全局类 gModuleDrawMgr.InitPar(); gModuleDeviceMgr.InitPar(); gModuleDrawMgr.SaveAllModuleProperty(); gModuleDeviceMgr.SaveAllModuleProperty(); if(gAuthorityMgr->IsAutoFactory()==false) { gAuthorityMgr->Lock(); } //初始化字体 CFontTypeMgr &FontTypeMgr = CFontTypeMgr::Instance(); FontTypeMgr.Initialize(); } //退出程序 void CLaiPuLaserApp::AppExit() { CWinApp::OnAppExit(); } int CLaiPuLaserApp::ExitInstance() { //TODO: 处理可能已添加的附加资源 AfxOleTerm(FALSE); //gModuleDeviceMgr.OnExitApp(); return CWinAppEx::ExitInstance(); } // CLaiPuLaserApp 消息处理程序 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 CAboutDlg::CAboutDlg():CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BOOL CAboutDlg::OnInitDialog() { CDialogEx::OnInitDialog(); CString s("软件启动时间:"); s+=gProgramLaserTuiHuo->GetAppOpenTime(); GetDlgItem(IDC_APP_OPEN_TIME)->SetWindowText(s); UpdateData(FALSE); CString AppMakeTime("软件编译时间: "); AppMakeTime += __DATE__; AppMakeTime += " "; AppMakeTime += __TIME__; GetDlgItem(IDC_APP_MAKE_TIME)->SetWindowText(AppMakeTime); #ifdef __USE_SUPER_DOG__ GetDlgItem(IDC_SUPER_DOG_INFO)->ShowWindow(SW_SHOW); //显示加密狗的时间 int DogYear =0; int DogMonth = 0; int DogDay = 0; gKernelMode.GetDogTime(&DogYear,&DogMonth,&DogDay); CString SuperDogTime; SuperDogTime.Format(_T("Hardware Time : %d / %d / %d"),DogYear,DogMonth,DogDay); CString str = "["; str += gEncryptionMgr->GetCurHardDiskSerialNum(); str += "]"; str += SuperDogTime; GetDlgItem(IDC_SUPER_DOG_INFO)->SetWindowText(str); #endif return TRUE; } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // 用于运行对话框的应用程序命令 void CLaiPuLaserApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } // CLaiPuLaserApp 自定义加载/保存方法 void CLaiPuLaserApp::PreLoadState() { BOOL bNameValid; CString strName; bNameValid = strName.LoadString(IDS_EDIT_MENU); ASSERT(bNameValid); GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT); } void CLaiPuLaserApp::LoadCustomState() { } void CLaiPuLaserApp::SaveCustomState() { } // CLaiPuLaserApp 消息处理程序