// CConfigDlg.cpp: 实现文件 // #include "pch.h" #include "resource.h" // 主符号 #include "CConfigDlg.h" #include "afxdialogex.h" //********************************通用配置类******************************** nsCFG::CConfigDlg::CConfigDlg(Dev_Type type, string& libName, string& fileName) : CDialogEx(IDD_ABOUTBOX) { m_emType = type; m_pLib = &libName; m_pCfgFile = &fileName; mLog::Debug("Enter CConfigDlg:{$}", (int)type); } void nsCFG::CConfigDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT1, m_Edit_Unitdll); DDX_Control(pDX, IDC_COMBO1, m_Combo_CfgFileList); } BEGIN_MESSAGE_MAP(nsCFG::CConfigDlg, CDialogEx) ON_BN_CLICKED(IDOK, &nsCFG::CConfigDlg::OnBnClickedOk) ON_CBN_SELCHANGE(IDC_COMBO1, &nsCFG::CConfigDlg::OnCbnSelchangeCombo1) END_MESSAGE_MAP() //初始化配置 BOOL nsCFG::CConfigDlg::OnInitDialog() { CDialogEx::OnInitDialog(); CString tempStr = ""; tempStr.Format("%s", m_pLib->c_str()); m_Edit_Unitdll.SetWindowText(tempStr); vector cfgFileList; string strCFGPath = GetProcessDirectory() + R"(\DriverConfig\)"; GetAllCFGFiles(strCFGPath, cfgFileList); for (int i = 0; i < cfgFileList.size(); i++) { m_Combo_CfgFileList.AddString(TEXT(cfgFileList[i].c_str())); if (cfgFileList[i] == m_pCfgFile->c_str()) { m_Combo_CfgFileList.SetCurSel(i); } } return TRUE; } //配置确认 void nsCFG::CConfigDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 CString tempStr; m_Edit_Unitdll.GetWindowText(tempStr); *m_pLib = tempStr; int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引 m_Combo_CfgFileList.GetLBText(index, tempStr);//根据当前位置的索引index找到具体内容 *m_pCfgFile = tempStr; mLog::Debug("Confirm Config:ID[{$}],lib[{$]],file[{$}]", (int)m_emType, m_pLib->c_str(), m_pCfgFile->c_str()); //SetToolDefaultConfig(glo_UnitList); CDialogEx::OnOK(); } //返回用户选择的配置文件 void nsCFG::CConfigDlg::OnCbnSelchangeCombo1() { CString log; try { //拿到索引位置 int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引 //获取索引位置的内容 CString strCFGFile; m_Combo_CfgFileList.GetLBText(index, strCFGFile);//根据当前位置的索引index找到具体内容 //弹出用户选中位置的具体内容 //MessageBox(strCFGFile); string procdir = GetProcessDirectory(); string strCFGPath = procdir + R"(\DriverConfig\)" + strCFGFile.GetBuffer(); mLog::Debug("Read module config_file:[{$}]", strCFGPath.c_str()); ResDataObject tempConfig; if (!(tempConfig.loadFile(strCFGPath.c_str()))) { mLog::Debug("Load reading module config_file[{$}]failed", strCFGPath.c_str()); return; } string strDLL(""); if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount("LoadDll") > 0) strDLL = (string)tempConfig[UnitTool_CONFIGURATION]["LoadDll"]; if (strDLL.rfind(".dll") != string::npos) { CString tempStr(strDLL.c_str()); m_Edit_Unitdll.SetWindowText(tempStr); } } catch (const ResDataObjectExption&) { mLog::Error("open file failed"); return; } catch (...) { mLog::Error("open file catch"); return; } } //********************************状态机配置类******************************** nsCFG::CSMachineCfgDlg::CSMachineCfgDlg(Dev_Type type, string& libName) : CDialogEx(IDD_ABOUTBOX1) { m_emType = type; m_pLib = &libName; mLog::Debug("Enter CSMachineCfgDlg:{$}", (int)type); } void nsCFG::CSMachineCfgDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, m_Combo_CfgFileList); } BEGIN_MESSAGE_MAP(nsCFG::CSMachineCfgDlg, CDialogEx) ON_BN_CLICKED(IDOK, &nsCFG::CSMachineCfgDlg::OnBnClickedOk) END_MESSAGE_MAP() //初始化配置 BOOL nsCFG::CSMachineCfgDlg::OnInitDialog() { CDialogEx::OnInitDialog(); vector cfgFileList; string strCFGPath = GetProcessDirectory(true); GetAllLibrary(strCFGPath, cfgFileList,"Machine"); for (int i = 0; i < cfgFileList.size(); i++) { m_Combo_CfgFileList.AddString(TEXT(cfgFileList[i].c_str())); if (cfgFileList[i] == m_pLib->c_str()) { m_Combo_CfgFileList.SetCurSel(i); } } return TRUE; } //配置确认 void nsCFG::CSMachineCfgDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 CString tempStr; int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引 m_Combo_CfgFileList.GetLBText(index, tempStr);//根据当前位置的索引index找到具体内容 *m_pLib = tempStr; mLog::Debug("Confirm Config:ID[{$}],lib[{$]]", (int)m_emType, m_pLib->c_str()); //SetToolDefaultConfig(glo_UnitList); CDialogEx::OnOK(); }