| | |
| | | #include "ChildFrm.h"
|
| | | #include "MTerm1Doc.h"
|
| | | #include "MTerm1View.h"
|
| | | #include "MTerm1LdsView.h"
|
| | | #include "MTerm1BldView.h"
|
| | | #include "MTerm1BnlView.h"
|
| | |
|
| | | #include "MTerm1CoilView.h"
|
| | | #include "MTerm1DataView.h"
|
| | |
|
| | | #include "MTerm1TestView.h"
|
| | | #include "MTerm1CtrlView.h"
|
| | | #include "MTerm1ProgTxt.h"
|
| | |
|
| | |
|
| | |
|
| | | #include "MTerm1CommDevView.h"
|
| | |
|
| | | #ifdef _DEBUG
|
| | | #define new DEBUG_NEW
|
| | |
| | |
|
| | | #include <devguid.h>
|
| | | #include <SetupAPI.h>
|
| | | //#include "HvSerialPort.h"
|
| | | //#include "CAnsiParser.h"
|
| | | //#include "CDataParser1.h"
|
| | | //#include "KLink.h"
|
| | |
|
| | | #include <eh.h>
|
| | | #include <dbghelp.h>
|
| | | #pragma comment(lib,"dbghelp.lib")
|
| | |
|
| | | #pragma comment(lib,"gdiplus.lib")
|
| | | #pragma comment(lib,"SetupAPI.lib")
|
| | | #pragma comment(lib,"gdiplus.lib")
|
| | |
|
| | | #include "../KLink1/KLink.h"
|
| | |
|
| | | #pragma comment(lib,"KLink1.lib")
|
| | | MHash MyCfg1;
|
| | | Logger MyLogger1;
|
| | |
|
| | | //KLinkProtocol MyKLProtocol1;
|
| | | // CSerialCom MySerialCom1;
|
| | | //HvSerialPort MyHvSerialPort1;
|
| | | Logger myLogger1;
|
| | |
|
| | | // CMTerm1App
|
| | |
|
| | |
| | | ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
|
| | | // 标准打印设置命令
|
| | | ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
|
| | | // ON_COMMAND(ID_COMUNICATION_SET, &CMTerm1App::OnComunicationSet)
|
| | | ON_COMMAND(ID_ENV_SET, &CMTerm1App::OnEnvSet)
|
| | | END_MESSAGE_MAP()
|
| | |
|
| | |
|
| | |
| | | CMTerm1App::CMTerm1App() noexcept
|
| | | {
|
| | | m_bHiColorIcons = TRUE;
|
| | |
|
| | | // 支持重新启动管理器
|
| | | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
|
| | | #ifdef _MANAGED
|
| | |
| | |
|
| | | // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
|
| | | //为 CompanyName.ProductName.SubProduct.VersionInformation
|
| | | SetAppID(_T("MTerm1.AppID.NoVersion"));
|
| | | SetAppID(_T("MultiTerminal2.AppID.NoVersion"));
|
| | |
|
| | | // TODO: 在此处添加构造代码,
|
| | | // 将所有重要的初始化放置在 InitInstance 中
|
| | |
| | |
|
| | | CWinAppEx::InitInstance();
|
| | |
|
| | | if (!AfxSocketInit())
|
| | | {
|
| | | AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
|
| | | return FALSE;
|
| | | }
|
| | |
|
| | | // 初始化 OLE 库
|
| | | if (!AfxOleInit())
|
| | |
| | | return FALSE;
|
| | | }
|
| | |
|
| | | Gdiplus::GdiplusStartupInput gdiplusStartupInput;
|
| | | Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
|
| | |
|
| | | AfxEnableControlContainer();
|
| | |
|
| | | EnableTaskbarInteraction();
|
| | | EnableTaskbarInteraction(FALSE);
|
| | |
|
| | | // 使用 RichEdit 控件需要 AfxInitRichEdit2()
|
| | | // AfxInitRichEdit2();
|
| | | AfxInitRichEdit2();
|
| | |
|
| | | // 标准初始化
|
| | | // 如果未使用这些功能并希望减小
|
| | |
| | | LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
|
| | |
|
| | |
|
| | | InitContextMenuManager();
|
| | |
|
| | | InitKeyboardManager();
|
| | |
|
| | | InitTooltipManager();
|
| | | CMFCToolTipInfo ttParams;
|
| | | ttParams.m_bVislManagerTheme = TRUE;
|
| | | theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
|
| | | RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
|
| | |
|
| | | // 注册应用程序的文档模板。 文档模板
|
| | | // 将用作文档、框架窗口和视图之间的连接
|
| | | CMultiDocTemplate* pDocTemplate;
|
| | | // CMultiDocTemplate* pDocTemplate;
|
| | | pDocTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | |
| | | if (!pDocTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(pDocTemplate);
|
| | | ///*
|
| | | // CMultiDocTemplate * m_pNewDocTemplate;
|
| | | ///*
|
| | | m_pLdsViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1LdsView));
|
| | | if (!m_pLdsViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pLdsViewTemplate);
|
| | |
|
| | | m_pBldViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1BldView));
|
| | | if (!m_pBldViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pBldViewTemplate);
|
| | |
|
| | | m_pBnlViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1BnlView));
|
| | | if (!m_pBnlViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pBnlViewTemplate);
|
| | |
|
| | | m_pCommDevViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1CommDevView));
|
| | | if (!m_pCommDevViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pCommDevViewTemplate);
|
| | |
|
| | |
|
| | | m_pCtrlViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1CtrlView));
|
| | | if (!m_pCtrlViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pCtrlViewTemplate);
|
| | |
|
| | | m_pProgViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1ProgTxt));
|
| | | if (!m_pProgViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pProgViewTemplate);
|
| | |
|
| | | m_pCoilViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1CoilView));
|
| | | if (!m_pCoilViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pCoilViewTemplate);
|
| | |
|
| | | m_pDataViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1DataView));
|
| | | if (!m_pDataViewTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pDataViewTemplate);
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | m_pNewDocTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
|
| | | RUNTIME_CLASS(CMTerm1Doc),
|
| | | RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
|
| | | RUNTIME_CLASS(CMTerm1TestView));
|
| | | if (!m_pNewDocTemplate)
|
| | | return FALSE;
|
| | | AddDocTemplate(m_pNewDocTemplate);
|
| | | //*/
|
| | | // 创建主 MDI 框架窗口
|
| | | CMainFrame* pMainFrame = new CMainFrame;
|
| | | if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
|
| | |
| | | CCommandLineInfo cmdInfo;
|
| | | ParseCommandLine(cmdInfo);
|
| | |
|
| | |
|
| | | if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
|
| | | cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
|
| | |
|
| | | // 调度在命令行中指定的命令。 如果
|
| | | // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
|
| | |
| | | // 主窗口已初始化,因此显示它并对其进行更新
|
| | | pMainFrame->ShowWindow(m_nCmdShow);
|
| | | pMainFrame->UpdateWindow();
|
| | |
|
| | | return TRUE;
|
| | | }
|
| | |
|
| | | int CMTerm1App::ExitInstance()
|
| | | {
|
| | | //TODO: 处理可能已添加的附加资源
|
| | | Gdiplus::GdiplusShutdown(m_gdiplusToken);
|
| | | // CoUninitialize();
|
| | | SaveMyConfig();
|
| | |
|
| | | AfxOleTerm(FALSE);
|
| | | //this->CleanState();
|
| | |
|
| | | return CWinAppEx::ExitInstance();
|
| | | }
|
| | |
| | | aboutDlg.DoModal();
|
| | | }
|
| | |
|
| | | // CMTerm1App 自定义加载/保存方法
|
| | |
|
| | | void CMTerm1App::PreLoadState()
|
| | | {
|
| | | BOOL bNameValid;
|
| | | CString strName;
|
| | | bNameValid = strName.LoadString(IDS_EDIT_MENU);
|
| | | ASSERT(bNameValid);
|
| | | GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
|
| | | bNameValid = strName.LoadString(IDS_EXPLORER);
|
| | | ASSERT(bNameValid);
|
| | | GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
|
| | | }
|
| | |
|
| | | void CMTerm1App::LoadCustomState()
|
| | | {
|
| | | }
|
| | |
|
| | | void CMTerm1App::SaveCustomState()
|
| | | {
|
| | | }
|
| | |
|
| | | // CMTerm1App 消息处理程序
|
| | |
|
| | | void CMTerm1App::OnFileNew()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | POSITION ps = m_pDocManager->GetFirstDocTemplatePosition();
|
| | | CDocTemplate *pDocTemplate = m_pDocManager->GetNextDocTemplate(ps);
|
| | | pDocTemplate->OpenDocumentFile(NULL);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | void CMTerm1App::OnComunicationSet()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | }
|
| | |
|
| | |
|
| | | void CMTerm1App::OnEnvSet()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | }
|
| | |
|
| | |
|
| | | int SysLog(CString s, int channel)
|
| | | {
|
| | | MyLogger1.LogTxt(s, channel);
|
| | | myLogger1.LogTxt(s, channel);
|
| | | return 1;
|
| | | }
|
| | |
|
| | | int DbgLog(CString s, int channel)
|
| | | {
|
| | | myLogger1.LogTxt(s, channel);
|
| | | return 1;
|
| | | }
|
| | |
|
| | |
| | | return res;
|
| | | }
|
| | |
|
| | | CString & intToString(int num)
|
| | | CString intToString(int num, int digit)
|
| | | {
|
| | | static CString Str1;
|
| | | Str1.Format(_T("%d"), num);
|
| | | if (digit != 0) {
|
| | | CString str2;
|
| | | str2.Format(_T("%%%dd"), digit);
|
| | | Str1.Format(str2, num);
|
| | |
|
| | | }else {
|
| | | Str1.Format(_T("%d"), num);
|
| | | }
|
| | |
|
| | | int k = Str1.GetLength();
|
| | | int j = (k - 1) / 3; //逗号个数
|
| | | int l = k - j * 3; //起始位置
|
| | |
| | |
|
| | | return Str1;
|
| | | }
|
| | | CString fixToString(int num, int digit, int fracdigit)
|
| | | {
|
| | | static CString Str1;
|
| | | if (digit != 0) {
|
| | | CString str2;
|
| | | str2.Format(_T("%%%dd"), digit);
|
| | | Str1.Format(str2, num);
|
| | |
|
| | | }
|
| | | else {
|
| | | Str1.Format(_T("%d"), num);
|
| | | }
|
| | |
|
| | | int k = Str1.GetLength();
|
| | | int j = (k - 1 - fracdigit) / 3; //逗号个数
|
| | | int l = k - fracdigit - j * 3; //起始位置
|
| | | for (int i = l; i < k -fracdigit + j; i += 4)
|
| | | {
|
| | | Str1.Insert(i, _T(","));
|
| | | }
|
| | | if (fracdigit>0) Str1.Insert(k - fracdigit + j, '.');
|
| | | return Str1;
|
| | | }
|
| | | CString & intToBinString(int num, int digits)
|
| | | {
|
| | | static CString Str1;
|
| | |
| | | mask >>= 1;
|
| | | }
|
| | | return Str1;
|
| | | }
|
| | |
|
| | | } |