// CChidSysCfg1.cpp: 实现文件 // #include "pch.h" #include "ConfigTool.h" #include "CChidSysCfg1.h" #include "afxdialogex.h" // CChidSysCfg1 对话框 IMPLEMENT_DYNAMIC(CChidSysCfg1, CDialogEx) CChidSysCfg1::CChidSysCfg1(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_PROP_SYSREG1, pParent) { } CChidSysCfg1::~CChidSysCfg1() { } void CChidSysCfg1::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CChidSysCfg1, CDialogEx) ON_WM_VSCROLL() ON_WM_SIZE() ON_WM_MOUSEHWHEEL() ON_WM_TIMER() END_MESSAGE_MAP() // CChidSysCfg1 消息处理程序 BOOL CChidSysCfg1::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 RECT rect0; GetClientRect(&rect0); m_nPropHeight = rect0.bottom - rect0.top; m_nFrameheight = 300; UpdateScrollInfo(); CString s1; s1.Format(_T("CChildSysCfg1 OnInitDialog")); SysLog(s1); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CChidSysCfg1::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); // TODO: 在此处添加消息处理程序代码 } int CChidSysCfg1::UpdateScrollInfo() { // TODO: 在此处添加实现代码. SCROLLINFO vinfo; vinfo.cbSize = sizeof(vinfo); vinfo.fMask = SIF_ALL; vinfo.nPage = m_nFrameheight;//滚动块自身的长短,通常有如下关系:其长度/滚动条长度(含两个箭头)=nPage/(nMax+2), //另外nPage取值-1时,滚动条会不见了。 vinfo.nMax = m_nPropHeight;// -m_nFrameheight;//滚动条所能滚动的最大值 vinfo.nMin = 0;//滚动条所能滚动的最小值 vinfo.nTrackPos = 0; SetScrollInfo(SB_VERT, &vinfo);//即使上述步骤一不做,使用此条语句也可以显示滚动条 CString s1; s1.Format(_T("CChildSysCfg1 UpdateScrollInfo")); SysLog(s1); return 0; } int CChidSysCfg1::VScrollBy(int nPos) { // TODO: 在此处添加实现代码. CString s1; int nMin, nMax; int TempPos; this->GetScrollRange(SB_VERT, &nMin, &nMax); TempPos = this->GetScrollPos(SB_VERT); TempPos += nPos; if (TempPos < 0) TempPos = 0; if (TempPos > nMax - m_nFrameheight) TempPos = nMax - m_nFrameheight; SetScrollPos(SB_VERT, TempPos); int nNewPos = -TempPos; int Scrolldel = nNewPos - m_nScrollPos; s1.Format(_T("PropSysReg Scroll %d %d %d %d"), m_nScrollPos, TempPos, nNewPos, Scrolldel); // SysLog(s1); this->ScrollWindow(0, Scrolldel); m_nScrollPos += Scrolldel; return 0; } void CChidSysCfg1::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: 在此添加消息处理程序代码和/或调用默认值 ///* CString s1; s1.Format(_T("PropSysReg OnVScroll %d %d"), nSBCode, nPos); // SysLog(s1); int nMin, nMax; int TempPos; if (pScrollBar == NULL) { this->GetScrollRange(SB_VERT, &nMin, &nMax); TempPos = this->GetScrollPos(SB_VERT); } else { pScrollBar->GetScrollRange(&nMin, &nMax); //取得滚动条范围 TempPos = pScrollBar->GetScrollPos(); } switch (nSBCode) { case SB_THUMBPOSITION://拖动滑块 case SB_THUMBTRACK: if (pScrollBar == NULL) { SetScrollPos(SB_VERT, nPos); } else { pScrollBar->SetScrollPos(nPos); } TempPos = nPos; break; case SB_LINEUP://点击上边/左边的箭头 TempPos-=10; if (TempPos < 0)TempPos = 0; if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); } else { pScrollBar->SetScrollPos(TempPos); } break; case SB_LINEDOWN://点击下边/右边的箭头 TempPos+=10; if (TempPos > nMax) TempPos = nMax; if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); } else { pScrollBar->SetScrollPos(TempPos); } break; case SB_PAGEUP: // 如果向上/左滚动一页 TempPos -= 100; if (TempPos < 0) TempPos = 0; if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); } else { pScrollBar->SetScrollPos(TempPos); } break; case SB_PAGEDOWN: // 如果向下/右滚动一页 TempPos += 100; if (TempPos > nMax) TempPos = nMax; if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); } else { pScrollBar->SetScrollPos(TempPos); } break; } int nNewPos = -TempPos; int Scrolldel = nNewPos - m_nScrollPos; s1.Format(_T("PropSysReg Scroll %d %d %d"), m_nScrollPos, nNewPos, Scrolldel); // SysLog(s1); this->ScrollWindow(0, Scrolldel); m_nScrollPos += Scrolldel; //*/ CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar); } void CChidSysCfg1::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt) { // 此功能要求 Windows Vista 或更高版本。 // _WIN32_WINNT 符号必须 >= 0x0600。 // TODO: 在此添加消息处理程序代码和/或调用默认值 ///* int nNewPos = m_nScrollPos; if (zDelta < 0) { this->ScrollWindow(0, 0); // if (-m_nScrollPos < m_nPropHeight - m_nFrameheight - 30) // nNewPos = m_nScrollPos - 30; // else // nNewPos = -(m_nPropHeight - m_nFrameheight); } else if (zDelta > 0) { this->ScrollWindow(0, 100); // if (-m_nScrollPos > 30) // nNewPos = m_nScrollPos + 30; // else // nNewPos = 0; } else { } // int Scrolldel = nNewPos - m_nScrollPos; // this->ScrollWindow(0, Scrolldel); // m_nScrollPos += Scrolldel; // GetDlgItem(IDC_SCROLLBAR1)->SetScrollPos(-m_nScrollPos); //*/ CDialogEx::OnMouseHWheel(nFlags, zDelta, pt); } void CChidSysCfg1::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent == 0) { KillTimer(0); DelayInit(); } else if (nIDEvent == 1) { } CDialogEx::OnTimer(nIDEvent); } int CChidSysCfg1::DelayInit() { return 0; } unsigned int type_ctrl_ids[6] = { IDC_COMBO_FROM_COIL_TYPE_1 ,IDC_COMBO_FROM_COIL_TYPE_2 ,IDC_COMBO_FROM_COIL_TYPE_3 ,IDC_COMBO_FROM_COIL_TYPE_4 ,IDC_COMBO_FROM_COIL_TYPE_5 ,IDC_COMBO_FROM_COIL_TYPE_6}; unsigned int addr_ctrl_ids[6] = { IDC_COMBO_FROM_COIL_ADDR_1 ,IDC_COMBO_FROM_COIL_ADDR_2 ,IDC_COMBO_FROM_COIL_ADDR_3 ,IDC_COMBO_FROM_COIL_ADDR_4 ,IDC_COMBO_FROM_COIL_ADDR_5 ,IDC_COMBO_FROM_COIL_ADDR_6 }; unsigned int bit_ctrl_ids[6] = { IDC_COMBO_FROM_COIL_BIT_1 ,IDC_COMBO_FROM_COIL_BIT_2 ,IDC_COMBO_FROM_COIL_BIT_3 ,IDC_COMBO_FROM_COIL_BIT_4 ,IDC_COMBO_FROM_COIL_BIT_5 ,IDC_COMBO_FROM_COIL_BIT_6 }; int CChidSysCfg1::ShowParams() { CString s1; s1.Format(_T("ShowParams")); SysLog(s1); // --------- 工作模式 --------------------------------------- //工作模式,跳线功能等,good 指示灯 // // ----------------------------------------------------------- //---------- 通讯端口1,RS232 ----------------------------- /* s1.Format(_T("mode %d"), psyscfg->PortParams[0].WorkMode); SysLog(s1); s1.Format(_T("station %d"), psyscfg->PortParams[0].Station); SysLog(s1); s1.Format(_T("baudrate %d"), psyscfg->PortParams[0].BaudRate); SysLog(s1); s1.Format(_T("bytesize %d"), psyscfg->PortParams[0].ByteSize); SysLog(s1); s1.Format(_T("stopbits %d"), psyscfg->PortParams[0].StopBits); SysLog(s1); s1.Format(_T("parity %d"), psyscfg->PortParams[0].Parity); SysLog(s1); s1.Format(_T("eofchar %d"), psyscfg->PortParams[0].EofChar); SysLog(s1); s1.Format(_T("sofchar %d"), psyscfg->PortParams[0].SofChar); SysLog(s1); s1.Format(_T("endtype %d"), psyscfg->PortParams[0].EndType); SysLog(s1); s1.Format(_T("recvaddr %d"), psyscfg->PortParams[0].RecvAddr); SysLog(s1); s1.Format(_T("recvsize %d"), psyscfg->PortParams[0].RecvSize); SysLog(s1); s1.Format(_T("endtime %d"), psyscfg->PortParams[0].EndTime); SysLog(s1); */ ((CComboBox *)GetDlgItem(IDC_COMBO_WORKMODE1))->SetCurSel(psyscfg->PortParams[0].WorkMode); ((CComboBox *)GetDlgItem(IDC_COMBO_STATION1))->SetCurSel(psyscfg->PortParams[0].Station); s1.Format(_T("%d"), psyscfg->PortParams[0].BaudRate * 100); ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE1))->SelectString(0, s1); ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE1))->SetWindowText(s1); ((CComboBox *)GetDlgItem(IDC_COMBO_BYTE_SIZE1))->SetCurSel(psyscfg->PortParams[0].ByteSize); ((CComboBox *)GetDlgItem(IDC_COMBO_STOP_BIT1))->SetCurSel(psyscfg->PortParams[0].StopBits); ((CComboBox *)GetDlgItem(IDC_COMBO_PARITY1))->SetCurSel(psyscfg->PortParams[0].Parity); ((CComboBox *)GetDlgItem(IDC_COMBO_EOF_CHAR1))->SetCurSel(psyscfg->PortParams[0].EofChar); ((CComboBox *)GetDlgItem(IDC_COMBO_SOF_CHAR1))->SetCurSel(psyscfg->PortParams[0].SofChar); ((CComboBox *)GetDlgItem(IDC_COMBO_END_TYPE1))->SetCurSel(psyscfg->PortParams[0].EndType); s1.Format(_T("%d"), psyscfg->PortParams[0].RecvAddr); ((CEdit *)GetDlgItem(IDC_EDIT_BUF_ADDR1))->SetWindowText(s1); s1.Format(_T("%d"), psyscfg->PortParams[0].RecvSize); ((CEdit *)GetDlgItem(IDC_EDIT_BUF_SIZE1))->SetWindowText(s1);; s1.Format(_T("%d"), psyscfg->PortParams[0].EndTime); ((CEdit *)GetDlgItem(IDC_EDIT_END_TIME1))->SetWindowText(s1);; //------------------------------------------------------------------ // --- 通讯端口2 RS485 ---------------------------- ((CComboBox *)GetDlgItem(IDC_COMBO_WORKMODE2))->SetCurSel(psyscfg->PortParams[1].WorkMode); ((CComboBox *)GetDlgItem(IDC_COMBO_STATION2))->SetCurSel(psyscfg->PortParams[1].Station); s1.Format(_T("%d"), psyscfg->PortParams[1].BaudRate * 100); ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE2))->SelectString(0, s1); ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE2))->SetWindowText(s1); ((CComboBox *)GetDlgItem(IDC_COMBO_BYTE_SIZE2))->SetCurSel(psyscfg->PortParams[1].ByteSize); ((CComboBox *)GetDlgItem(IDC_COMBO_STOP_BIT2))->SetCurSel(psyscfg->PortParams[1].StopBits); ((CComboBox *)GetDlgItem(IDC_COMBO_PARITY2))->SetCurSel(psyscfg->PortParams[1].Parity); ((CComboBox *)GetDlgItem(IDC_COMBO_EOF_CHAR2))->SetCurSel(psyscfg->PortParams[1].EofChar); ((CComboBox *)GetDlgItem(IDC_COMBO_SOF_CHAR2))->SetCurSel(psyscfg->PortParams[1].SofChar); ((CComboBox *)GetDlgItem(IDC_COMBO_END_TYPE2))->SetCurSel(psyscfg->PortParams[1].EndType); s1.Format(_T("%d"), psyscfg->PortParams[1].RecvAddr); ((CEdit *)GetDlgItem(IDC_EDIT_BUF_ADDR2))->SetWindowText(s1); s1.Format(_T("%d"), psyscfg->PortParams[1].RecvSize); ((CEdit *)GetDlgItem(IDC_EDIT_BUF_SIZE2))->SetWindowText(s1);; s1.Format(_T("%d"), psyscfg->PortParams[1].EndTime); ((CEdit *)GetDlgItem(IDC_EDIT_END_TIME2))->SetWindowText(s1);; //------------------------------------------------------------------ // --- 输入滤波 ---------------------------- int i = 0; i = psyscfg->InputParams[0].Filter0; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_1))->SetCurSel(i); i = psyscfg->InputParams[0].Filter1; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_2))->SetCurSel(i); i = psyscfg->InputParams[1].Filter0; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_3))->SetCurSel(i); i = psyscfg->InputParams[1].Filter1; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_4))->SetCurSel(i); i = psyscfg->InputParams[2].Filter0; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_5))->SetCurSel(i); i = psyscfg->InputParams[2].Filter1; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_6))->SetCurSel(i); i = psyscfg->InputParams[3].Filter0; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_7))->SetCurSel(i); i = psyscfg->InputParams[3].Filter1; ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_8))->SetCurSel(i); //------------------------------------------------------------------ // --- 输出保持 ---------------------------- i = psyscfg->OutputParams[0].Hold1; ((CComboBox *)GetDlgItem(IDC_COMBO_OUTPUT_SET_1))->SetCurSel(i); i = psyscfg->OutputParams[0].Hold2; ((CComboBox *)GetDlgItem(IDC_COMBO_OUTPUT_SET_1))->SetCurSel(i); //------------------------------------------------------------------ // --- 输出端口映射 ---------------------------- for (int i = 0; i < 6; i++) { unsigned short bytebitaddr = psyscfg->OutMappings[i]; s1.Format(_T("mappig %d %04x"), i, bytebitaddr); SysLog(s1); unsigned char ntype = (bytebitaddr & 0xf000) >> 12; unsigned char byteaddr = (bytebitaddr & 0x0ff0) >> 4; unsigned char bitoff = bytebitaddr & 0x000f; ((CComboBox *)GetDlgItem(type_ctrl_ids[i]))->SetCurSel(ntype); ((CComboBox *)GetDlgItem(addr_ctrl_ids[i]))->SetCurSel(byteaddr); ((CComboBox *)GetDlgItem(bit_ctrl_ids[i]))->SetCurSel(bitoff); } //------------------------------------------------------------------ return 0; } int CChidSysCfg1::GetParams() { CString s1; s1.Format(_T("GetParams")); SysLog(s1); for (int i = 0; i < 6; i++) { unsigned char ntype = ((CComboBox *)GetDlgItem(type_ctrl_ids[i]))->GetCurSel(); unsigned char byteaddr = ((CComboBox *)GetDlgItem(addr_ctrl_ids[i]))->GetCurSel(); unsigned char bitoff = ((CComboBox *)GetDlgItem(bit_ctrl_ids[i]))->GetCurSel(); unsigned short bytebitaddr = (ntype << 12) + (byteaddr << 4) + (bitoff); psyscfg->OutMappings[i] = bytebitaddr; s1.Format(_T("mappig %d %04x"), i, bytebitaddr); SysLog(s1); } return 0; } BOOL CChidSysCfg1::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 CString s1; if (pMsg->hwnd && pMsg->message == WM_MOUSEWHEEL) { if (pMsg->hwnd != this->m_hWnd) { pMsg->hwnd = this->m_hWnd; //return TRUE; } /* GetClassName(pMsg->hwnd, s1.GetBuffer(256), 256); s1.ReleaseBuffer(); if (s1.Find(_T("COMBOBOX")) == 0) { return TRUE; } */ } return CDialogEx::PreTranslateMessage(pMsg); } BOOL CChidSysCfg1::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) { // TODO: 在此添加专用代码和/或调用基类 //if (message == WM_MOUSEWHEEL) return true; return CDialogEx::OnChildNotify(message, wParam, lParam, pLResult); }