// CDialogSysRegSet.cpp: 实现文件 // #include "pch.h" #include "MTerm1.h" #include "DialogSysRegSet.h" #include "afxdialogex.h" #include #include #pragma comment(lib, "msxml6.lib") #include "MTerm1Doc.h" MHash gsd1; // CDialogSysRegSet 对话框 IMPLEMENT_DYNAMIC(CDialogSysRegSet, CDialogEx) CDialogSysRegSet::CDialogSysRegSet(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_SYSREG_SET, pParent) { } CDialogSysRegSet::~CDialogSysRegSet() { } void CDialogSysRegSet::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_SCROLLBAR1, m_prop_scrollbar1); DDX_Control(pDX, IDC_LIST_SEL1, m_listSel1); } BEGIN_MESSAGE_MAP(CDialogSysRegSet, CDialogEx) ON_WM_VSCROLL() ON_WM_MOUSEWHEEL() ON_LBN_SELCHANGE(IDC_LIST_SEL1, &CDialogSysRegSet::OnLbnSelchangeListSel1) ON_BN_CLICKED(IDC_BUTTON_READ_FROM_PLC, &CDialogSysRegSet::OnBnClickedButtonReadFromPlc) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON_WRITE_TO_PLC, &CDialogSysRegSet::OnBnClickedButtonWriteToPlc) ON_BN_CLICKED(IDC_BUTTON_READ_FROM_PLC2, &CDialogSysRegSet::OnBnClickedButtonReadFromPlc2) END_MESSAGE_MAP() // CDialogSysRegSet 消息处理程序 int CDialogSysRegSet::LoadDeviceDescriptionFile() { // TODO: 在此处添加实现代码. gsd1.LoadFromFile(_T("FP0Ext.cfg")); CString s1; s1 = gsd1["configs"]["output1"]; SysLog(s1); s1 = MyCfg1["dafd"]["sdfdf"]; return 0; } int CDialogSysRegSet::AddPropPage(CString sName, CMyPropPage * rDlg, int IDD, void * DataAddr) { // TODO: 在此处添加实现代码. m_listSel1.AddString(sName); if (rDlg->GetSafeHwnd() == NULL ) { } m_PropPages[m_nTotalProp] = rDlg; PropPageIDD[m_nTotalProp] = IDD; rDlg->DataPtr = DataAddr; m_nTotalProp++; return 0; } int CDialogSysRegSet::testXmlParser() { // TODO: 在此处添加实现代码. CString s1; using namespace std; // TODO: 在此添加额外的初始化 CoInitialize(NULL); //定义DOM模型中的文档对象 CComPtr spXmldoc; //初始化库对象 HRESULT hr = spXmldoc.CoCreateInstance(CLSID_DOMDocument60); s1.Format(_T("Create Instance Hr = %d "), hr); SysLog(s1); if (SUCCEEDED(hr)) { //读取 xml 文件 char *pPath = "config1.xml"; CComBSTR Path = CComBSTR(pPath); //将XML文件导入内存中的文档对象 VARIANT_BOOL success; hr = spXmldoc->load(CComVariant(Path), &success); s1.Format(_T("Load File Hr = %d "), hr); SysLog(s1); CComPtr spChildren; spXmldoc->get_childNodes(&spChildren); int i = 0; long numChildren = 0; spChildren->get_length(&numChildren); s1.Format(_T("num of Children = %d "), numChildren); SysLog(s1); for (int i = 0; i < numChildren; i++) { CComPtr spNode; CComBSTR NodeName; spChildren->get_item(i, &spNode); spNode->get_nodeName(&NodeName); CComPtr spChildren2; spNode->get_childNodes(&spChildren2); long numChildren2 = 0; spChildren2->get_length(&numChildren2); CString s2; s2 = NodeName; s1.Format(_T("Root node %d name = %s num of Child %d "), i, s2, numChildren2); SysLog(s1); } // spXmldoc // spXmldoc->Release(); // spXmldoc.Release(); } return 0; } CMTerm1Doc * CDialogSysRegSet::GetDocument() { // TODO: 在此处添加实现代码. CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); return pDoc; } BOOL CDialogSysRegSet::OnInitDialog() { CDialogEx::OnInitDialog(); testXmlParser(); LoadDeviceDescriptionFile(); SetTimer(0, 10, NULL); // m_prop_scrollbar1.SetScrollRange(1, 100); // m_prop_scrollbar1.SetScrollPos(20); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CDialogSysRegSet::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent == 0) { KillTimer(0); DelayInit(); } else if (nIDEvent == 1) { } CDialogEx::OnTimer(nIDEvent); } int CDialogSysRegSet::DelayInit() { // TODO: 在此处添加实现代码. CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument(); unsigned short DCount = 120; unsigned short nCount=0; int res = pDoc->MyKLink1.ReadDataWord(1, KLDataSysCfg, 0, DCount, &nCount, m_databuf1); CString s1; s1.Format(_T("ReadDataWord = %d %d %p %p"), res,nCount, m_databuf1, &pSysCfg->PortParams[0]); SysLog(s1); s1.Empty(); s1.Append(_T("\r\n")); for (int i = 0; i < nCount / 2; i++) { if ((i & 0x7) == 0) s1.AppendFormat(_T("%02X "),i); s1.AppendFormat(_T("%04X "), m_databuf1[i]); if (((i + 1) & 0x7) == 0) s1.Append(_T("\r\n")); } SysLog(s1); pSysCfg = (pKMSysCfg)m_databuf1; m_listSel1.GetCount(); AddPropPage(_T("工作模式设置1"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, &pSysCfg->workmode); ///* AddPropPage(_T("内存分配1"), &m_propmemcfg1, IDD_PROP_MEM_CFG, 0); AddPropPage(_T("保持/非保持11"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, 0); AddPropPage(_T("保持/非保持21"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, 0); AddPropPage(_T("232通信端口设置1"), &m_propcommcfg1, IDD_PROP_COMM_CFG, &pSysCfg->PortParams[0]); AddPropPage(_T("485通信端口设置1"), &m_propcommcfg2, IDD_PROP_COMM_CFG, &pSysCfg->PortParams[1]); AddPropPage(_T("输入时间常数设置1"), &m_propinputcfg1, IDD_PROP_INPUT_CFG, &pSysCfg->InputParams[0]); // AddPropPage(_T("输入时间常数设置2"), &m_propinputcfg2, IDD_PROP_INPUT_CFG, 0); AddPropPage(_T("输出保持时间设置1"), &m_propoutputcfg1, IDD_PROP_OUTPUT_SET, 0); AddPropPage(_T("输出保持时间设置2"), &m_propoutputcfg2, IDD_PROP_OUTPUT_SET, 0); AddPropPage(_T("485通信端口设置2"), &m_propcommcfg3, IDD_PROP_COMM_CFG, 0); AddPropPage(_T("内置SPI端口设置1"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, 0); AddPropPage(_T("外置扩展SPI端口设置1"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, 0); //*/ //GetDlgItem(IDC_STATIC_PROP)-> GetDlgItem(IDC_STATIC_PROP)->GetClientRect(&rect1); m_nFrameheight = rect1.bottom - rect1.top; GetDlgItem(IDC_STATIC_PROP)->ClientToScreen(&rect1); this->ScreenToClient(&rect1); m_propsysreg1.Create(IDD_PROP_SYSREG1, this); m_propsysreg1.EnableWindow(true); m_propsysreg1.GetClientRect(&rect0); m_nPropHeight = rect0.bottom - rect0.top; // m_propsysreg1.ShowWindow(SW_SHOW); m_propmodecfg1.Create(IDD_PROP_MODE_CFG1, this); m_propmodecfg1.EnableWindow(true); m_propmodecfg1.MoveWindow(&rect1, true); m_propmodecfg1.ShowWindow(SW_SHOW); PropPageInited[0] = 1; /* m_propmemcfg1.Create(IDD_PROP_MEM_CFG, this); m_propmemcfg1.MoveWindow(&rect1, true); m_propmemcfg1.EnableWindow(true); m_propcommcfg1.Create(IDD_PROP_COMM_CFG, this); m_propcommcfg1.MoveWindow(&rect1, true); m_propcommcfg1.EnableWindow(true); m_propcommcfg2.Create(IDD_PROP_COMM_CFG, this); m_propcommcfg2.MoveWindow(&rect1, true); m_propcommcfg2.EnableWindow(true); m_propcommcfg3.Create(IDD_PROP_COMM_CFG, this); m_propcommcfg3.MoveWindow(&rect1, true); m_propcommcfg3.EnableWindow(true); m_propinputcfg1.Create(IDD_PROP_INPUT_CFG, this); m_propinputcfg1.MoveWindow(&rect1, true); m_propinputcfg1.EnableWindow(true); m_propinputcfg2.Create(IDD_PROP_INPUT_CFG, this); m_propinputcfg2.MoveWindow(&rect1, true); m_propinputcfg2.EnableWindow(true); m_propinputcfg3.Create(IDD_PROP_INPUT_CFG, this); m_propinputcfg3.MoveWindow(&rect1, true); m_propinputcfg3.EnableWindow(true); m_propinputcfg4.Create(IDD_PROP_INPUT_CFG, this); m_propinputcfg4.MoveWindow(&rect1, true); m_propinputcfg4.EnableWindow(true); m_propoutputcfg1.Create(IDD_PROP_OUTPUT_SET, this); m_propoutputcfg1.MoveWindow(&rect1, true); m_propoutputcfg1.EnableWindow(true); m_propoutputcfg2.Create(IDD_PROP_OUTPUT_SET, this); m_propoutputcfg2.MoveWindow(&rect1, true); m_propoutputcfg2.EnableWindow(true); m_propoutputcfg3.Create(IDD_PROP_OUTPUT_SET, this); m_propoutputcfg3.MoveWindow(&rect1, true); m_propoutputcfg3.EnableWindow(true); m_propoutputcfg4.Create(IDD_PROP_OUTPUT_SET, this); m_propoutputcfg4.MoveWindow(&rect1, true); m_propoutputcfg4.EnableWindow(true); */ m_propsysreg1.MoveWindow(&rect1, true); int nNewPos = m_nScrollPos; int Scrolldel = nNewPos - m_nScrollPos; m_propsysreg1.ScrollWindow(0, Scrolldel); m_nScrollPos += Scrolldel; SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = m_nPropHeight;//你滑动画面的高度 si.nPage = m_nFrameheight; //这个是你显示画面的高度 si.nPos = 0;//这个是滑块的位置 初始化的时候是0 以后会根据你的操作变动 // GetDlgItem(IDC_STATIC_PROP)->SetScrollInfo(SB_VERT, &si); // m_propsysreg1.SetScrollInfo(SB_VERT, &si); m_prop_scrollbar1.SetScrollInfo(&si, true); return 0; } void CDialogSysRegSet::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: 在此添加消息处理程序代码和/或调用默认值 int nMin, nMax; pScrollBar->GetScrollRange(&nMin, &nMax); //取得滚动条范围 int TempPos = pScrollBar->GetScrollPos(); CString s1; // s1.Format(_T("DialogSysReg OnVScroll %d %d %d"), nSBCode, nPos,TempPos); // SysLog(s1); switch (nSBCode) { case SB_THUMBPOSITION://拖动滑块 case SB_THUMBTRACK: pScrollBar->SetScrollPos(nPos); TempPos = nPos; break; case SB_LINEUP://点击上边/左边的箭头 if (TempPos > 1) { TempPos--; } pScrollBar->SetScrollPos(TempPos); break; case SB_LINEDOWN://点击下边/右边的箭头 if (TempPos < nMax) { TempPos++; } pScrollBar->SetScrollPos(TempPos); break; case SB_PAGEUP: // 如果向上/左滚动一页 if (TempPos >10) TempPos -= 10; pScrollBar->SetScrollPos(TempPos); break; case SB_PAGEDOWN: // 如果向下/右滚动一页 if (TempPos < nMax - 10) TempPos += 10; pScrollBar->SetScrollPos(TempPos); break; } int nNewPos = -TempPos; int Scrolldel = nNewPos - m_nScrollPos; // s1.Format(_T("DialogSysReg Scroll %d %d %d"), m_nScrollPos, nNewPos, Scrolldel); // SysLog(s1); m_propsysreg1.ScrollWindow(0, Scrolldel); m_nScrollPos += Scrolldel; // m_propsysreg1.ScrollWindow(0, -TempPos); CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar); } BOOL CDialogSysRegSet::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { // TODO: 在此添加消息处理程序代码和/或调用默认值 /* int nNewPos=m_nScrollPos; if (zDelta < 0) { if (-m_nScrollPos < m_nPropHeight -m_nFrameheight - 30) nNewPos = m_nScrollPos - 30; else nNewPos = - (m_nPropHeight - m_nFrameheight); } else if (zDelta > 0) { if (-m_nScrollPos > 30) nNewPos = m_nScrollPos + 30; else nNewPos = 0; } else { } int Scrolldel = nNewPos - m_nScrollPos; m_propsysreg1.ScrollWindow(0, Scrolldel); m_nScrollPos += Scrolldel; m_prop_scrollbar1.SetScrollPos(-m_nScrollPos); */ return CDialogEx::OnMouseWheel(nFlags, zDelta, pt); } void CDialogSysRegSet::OnLbnSelchangeListSel1() { // TODO: 在此添加控件通知处理程序代码 CString s1; int j = m_listSel1.GetCurSel(); s1.Format(_T("LbnSelChange %d"),j); SysLog(s1); m_PropPages[m_nCurProp]->ShowWindow(SW_HIDE); if (m_PropPages[j]->GetSafeHwnd() == NULL) { m_PropPages[j]->Create(PropPageIDD[j], this); m_PropPages[j]->GetData(); } m_PropPages[j]->MoveWindow(&rect1, true); m_PropPages[j]->EnableWindow(true); m_PropPages[j]->ShowWindow(SW_SHOW); /* switch (j) { case 0: m_propmodecfg1.ShowWindow(SW_SHOW); m_propmodecfg1.MoveWindow(&rect1, true); break; case 1: m_propmemcfg1.ShowWindow(SW_SHOW); m_propmodecfg1.MoveWindow(&rect1, true); break; case 2: //m_propmodecfg1.ShowWindow(SW_SHOW); break; case 3: //m_propmodecfg1.ShowWindow(SW_SHOW); break; case 4: m_propcommcfg1.ShowWindow(SW_SHOW); m_propmodecfg1.MoveWindow(&rect1, true); break; case 5: m_propcommcfg2.ShowWindow(SW_SHOW); m_propmodecfg1.MoveWindow(&rect1, true); break; case 6: m_propinputcfg1.ShowWindow(SW_SHOW); break; case 7: m_propinputcfg2.ShowWindow(SW_SHOW); break; case 8: m_propinputcfg3.ShowWindow(SW_SHOW); break; case 9: m_propinputcfg4.ShowWindow(SW_SHOW); break; case 10: m_propoutputcfg1.ShowWindow(SW_SHOW); break; case 11: m_propoutputcfg2.ShowWindow(SW_SHOW); break; case 12: m_propoutputcfg3.ShowWindow(SW_SHOW); break; case 13: m_propoutputcfg4.ShowWindow(SW_SHOW); break; case 14: m_propcommcfg3.ShowWindow(SW_SHOW); break; default: break; } */ m_nCurProp = j; } void CDialogSysRegSet::OnBnClickedButtonReadFromPlc() { // TODO: 在此添加控件通知处理程序代码 CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument(); unsigned short buf1[256]; unsigned short DCount=150; unsigned short nCount; CString s1; s1.Format(_T("sizeof (syscfg) %d"), sizeof(stKMSysCfg)); SysLog(s1); int res = pDoc->MyKLink1.ReadSysCfgData(1, 0, DCount, &nCount, buf1); s1.Format(_T("ReadDataWord = %d %d"), res, nCount); SysLog(s1); s1.Empty(); s1.Append(_T("\r\n")); for (int i = 0; i < nCount/2; i++) { if ((i & 0x7) == 0) s1.AppendFormat(_T("%02X "), i); s1.AppendFormat(_T("%04X "), buf1[i]); if (((i+1) & 0x7) == 0) s1.Append(_T("\r\n")); } SysLog(s1); for (int i = 0; i < m_nTotalProp; i++) { if (PropPageInited[i]) { m_PropPages[i]->GetData(); } } } void CDialogSysRegSet::OnBnClickedButtonWriteToPlc() { // TODO: 在此添加控件通知处理程序代码 CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument(); unsigned short DCount = 120; unsigned short nCount; unsigned short buf2[256]; for (int i=0;i<256;i++) { buf2[i] = i; } CString s1; pSysCfg->PortParams[0].BaudRate++; s1.Format(_T("sizeof (syscfg) %d"), sizeof(stKMSysCfg)); SysLog(s1); int res = pDoc->MyKLink1.WriteSysCfgData(1, 0, DCount, m_databuf1); s1.Format(_T("Write syscfg = %d "), res); SysLog(s1); } void CDialogSysRegSet::OnBnClickedButtonReadFromPlc2() { // TODO: 在此添加控件通知处理程序代码 CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument(); unsigned short buf1[256]; unsigned short DCount = 150; unsigned short nCount; CString s1; s1.Format(_T("sizeof (syscfg) %d"), sizeof(stKMSysCfg)); SysLog(s1); int res = pDoc->MyKLink1.ReadDataWord(1, KLDataSysCfg,0,DCount, &nCount, buf1); s1.Format(_T("ReadDataWord = %d %d"), res, nCount); SysLog(s1); s1.Empty(); s1.Append(_T("\r\n")); for (int i = 0; i < nCount / 2; i++) { if ((i & 0x7) == 0) s1.AppendFormat(_T("%02X "), i); s1.AppendFormat(_T("%04X "), buf1[i]); if (((i + 1) & 0x7) == 0) s1.Append(_T("\r\n")); } SysLog(s1); }