| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // IOMonitoringDlg.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "IOMonitoringDlg.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | #define TIMER_INIT 1 |
| | | #define TIMER_READ_PLC_DATA 2 |
| | | |
| | | // CIOMonitoringDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CIOMonitoringDlg, CDialogEx) |
| | | |
| | | CIOMonitoringDlg::CIOMonitoringDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_IO_MONITORING, pParent) |
| | | { |
| | | m_nCurrentPage = 1; |
| | | m_nTotalPages = 1; |
| | | m_nRowsPerPage = 10; |
| | | m_nCols = 6; |
| | | } |
| | | |
| | | CIOMonitoringDlg::~CIOMonitoringDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | |
| | | ClearDynamicControls(); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_STATIC_PAGE_NUMBER, m_staticPageNum); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::SetIOManager(const std::string& machineName) |
| | | { |
| | | IOManager manager; |
| | | manager.loadFromFile(machineName); |
| | | m_machineName = machineName; |
| | | |
| | | // å è½½æ°æ® |
| | | m_displayData = manager.GetMachineData(machineName); |
| | | |
| | | // 计ç®é¡µæ° |
| | | m_nCurrentPage = 1; |
| | | m_nTotalPages = (m_displayData.size() + m_nRowsPerPage - 1) / m_nRowsPerPage; |
| | | } |
| | | |
| | | void CIOMonitoringDlg::SetPLC(CPLC* pPLC) |
| | | { |
| | | ASSERT(pPLC); |
| | | m_pPLC = pPLC; |
| | | } |
| | | |
| | | CFont* CIOMonitoringDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second; |
| | | } |
| | | |
| | | CFont* font = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font; |
| | | } |
| | | |
| | | void CIOMonitoringDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåæææ§ä»¶ï¼åºç¨é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | // æ ¹æ®æ§ä»¶é«åº¦å¨æè°æ´åä½å¤§å° |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | if (fontSize < 24) fontSize = 24; |
| | | |
| | | // è·åæå建åä½ |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // å·æ°æ§ä»¶æ¾ç¤º |
| | | } |
| | | |
| | | void CIOMonitoringDlg::UpdatePageInfo() |
| | | { |
| | | // æ ¼å¼å页ç ä¿¡æ¯ä¸º "å½å页/æ»é¡µæ°" |
| | | CString pageInfo; |
| | | pageInfo.Format(_T("%d/%d 页"), m_nCurrentPage, m_nTotalPages); |
| | | m_staticPageNum.SetWindowText(pageInfo); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::CreateDynamicControls() |
| | | { |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | |
| | | // è·åæé®çå¤§å° |
| | | CWnd* pPrevButton = GetDlgItem(IDC_BUTTON_PREV_PAGE); |
| | | CWnd* pNextButton = GetDlgItem(IDC_BUTTON_NEXT_PAGE); |
| | | |
| | | CRect prevButtonRect, nextButtonRect; |
| | | pPrevButton->GetWindowRect(&prevButtonRect); |
| | | pNextButton->GetWindowRect(&nextButtonRect); |
| | | |
| | | // è½¬æ¢æé®åæ å°å¯¹è¯æ¡çåæ ç³»ç» |
| | | ScreenToClient(&prevButtonRect); |
| | | ScreenToClient(&nextButtonRect); |
| | | |
| | | int buttonHeight = prevButtonRect.Height(); // æé®çé«åº¦ |
| | | int topMargin = rect.Height() * 0.05; // é¡¶é¨ä¿ç 5% çé«åº¦ |
| | | int bottomMargin = buttonHeight + topMargin; // åºé¨ä¿çæé®é«åº¦å é´è· |
| | | int sideMargin = topMargin; // å·¦å³é´è·ä¸é¡¶é¨é´è·ç¸å |
| | | int groupSpacing = 20; // 两ç»ä¹é´çé´è· |
| | | int verticalSpacing = 10; // åç´é´è· |
| | | |
| | | // æ¯è¡é«åº¦åå宽度 |
| | | int availableHeight = rect.Height() - topMargin - bottomMargin; |
| | | int rowHeight = (availableHeight / m_nRowsPerPage) - verticalSpacing; // æ§ä»¶é«åº¦å
å«é´è· |
| | | |
| | | int availableWidth = rect.Width() - 2 * sideMargin; // å¯ç¨å®½åº¦ï¼åå»å·¦å³é´è·ï¼ |
| | | int colWidthSmall = availableWidth / 14; // å°å®½åº¦åæ´å° |
| | | int colWidthLarge = availableWidth * 4 / 14; // å¤§å®½åº¦åæ¯ä¾ |
| | | int groupWidth = colWidthSmall * 2 + colWidthLarge; // æ¯ç»æ»å®½åº¦ |
| | | |
| | | for (int i = 0; i < m_nRowsPerPage; ++i) { |
| | | // æ¯ä¸è¡çèµ·å§ Y åæ |
| | | int y = topMargin + i * (rowHeight + verticalSpacing); |
| | | |
| | | // å建第 1 ç» (0, 1, 2) |
| | | int x = sideMargin; // ä»å·¦è¾¹è·å¼å§ |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("X1000"), false, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("æè¿°ææ¬"), false); |
| | | |
| | | // 第 2 ç»èµ·å§ä½ç½®ï¼å ä¸ç»é´è· |
| | | x += colWidthLarge + groupSpacing; |
| | | |
| | | // å建第 2 ç» (3, 4, 5) |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter, [this, i]() { |
| | | // èªå®ä¹ç¹å»äºä»¶çé»è¾ |
| | | auto* pControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 3]); |
| | | CString currentText; |
| | | pControl->GetWindowText(currentText); |
| | | |
| | | BOOL bOn = FALSE; |
| | | if (currentText == _T("OFF")) { |
| | | //pControl->SetBkColor(RGB(0, 255, 0)); // 绿è²èæ¯ |
| | | //pControl->SetText(_T("ON")); // æ´æ°ææ¬ä¸º ON |
| | | bOn = TRUE; |
| | | } |
| | | else { |
| | | //pControl->SetBkColor(RGB(255, 0, 0)); // 红è²èæ¯ |
| | | //pControl->SetText(_T("OFF")); // æ´æ°ææ¬ä¸º OFF |
| | | bOn = FALSE; |
| | | } |
| | | |
| | | pControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 4]); |
| | | pControl->GetWindowText(currentText); |
| | | |
| | | int nAddress; |
| | | MC::SOFT_COMPONENT component; |
| | | if (ParsePLCAddress(currentText, component, nAddress) && m_pPLC) { |
| | | TRACE("å°åè§£ææå: %s\n", currentText); |
| | | m_pPLC->writeBit(component, nAddress, bOn, [](IMcChannel* pChannel, int addr, DWORD value, int flag) { |
| | | if (flag == 0) { |
| | | TRACE("åå
¥æå: å°å: %d, å¼: %lu\n", addr, value); |
| | | } |
| | | else { |
| | | TRACE("åå
¥å¤±è´¥: å°å: %d, é误ç : %d\n", addr, flag); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("Y1010"), false, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("æè¿°ææ¬"), false); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder, TextAlign alignment, std::function<void()> clickCallback) |
| | | { |
| | | // åå»ºå¨ææ§ä»¶ |
| | | CBLLabel* pStatic = new CBLLabel(); |
| | | DWORD style = WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE; // ç¡®ä¿åç´å±
ä¸ |
| | | if (hasBorder) { |
| | | style |= WS_BORDER; // æ·»å è¾¹æ¡ |
| | | } |
| | | pStatic->Create(text, style, CRect(x, y, x + width, y + height), this); |
| | | |
| | | // è®¾ç½®ææ¬å¯¹é½æ¹å¼ |
| | | pStatic->SetAlignment(alignment); |
| | | |
| | | // è®¾ç½®å¨æåä½è°æ´ï¼å¹¶è®¾ç½®åä½å¤§å°ï¼å¨æåä½ä¼æ ¹æ®æ§ä»¶å¤§å°è°æ´ï¼ |
| | | int nSize = height / 3; |
| | | CFont* pFont = GetOrCreateFont(nSize); |
| | | pStatic->SetFont(pFont); |
| | | pStatic->SetFontSize(nSize); |
| | | pStatic->SetDynamicFont(TRUE); |
| | | |
| | | // 设置åè° |
| | | if (clickCallback) { |
| | | pStatic->SetClickCallback(clickCallback); |
| | | } |
| | | |
| | | // å卿§ä»¶æé |
| | | m_staticControls.push_back(pStatic); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::DisplayCurrentPage() |
| | | { |
| | | int startIndex = (m_nCurrentPage - 1) * m_nRowsPerPage; |
| | | int endIndex = min(startIndex + m_nRowsPerPage, static_cast<int>(m_displayData.size())); |
| | | |
| | | m_inputPLCAddresses.clear(); |
| | | m_outputPLCAddresses.clear(); |
| | | |
| | | for (int i = 0; i < m_nRowsPerPage; ++i) { |
| | | int row = i; |
| | | |
| | | if (startIndex + i < endIndex) { |
| | | const auto& data = m_displayData[startIndex + i]; |
| | | |
| | | // æ·»å PLC å°åå°å®¹å¨ä¸ |
| | | m_inputPLCAddresses.push_back(CString(data.inputAddress.c_str())); // 1 å |
| | | m_outputPLCAddresses.push_back(CString(data.outputAddress.c_str())); // 4 å |
| | | |
| | | // æ¾ç¤ºæ§ä»¶å¹¶è®¾ç½®å
容 |
| | | m_staticControls[row * m_nCols + 0]->SetWindowText(_T("OFF")); |
| | | m_staticControls[row * m_nCols + 0]->ShowWindow(SW_SHOW); |
| | | m_staticControls[row * m_nCols + 0]->SetBkColor(RGB(255, 0, 0)); |
| | | |
| | | m_staticControls[row * m_nCols + 1]->SetWindowText(CString(data.inputAddress.c_str())); |
| | | m_staticControls[row * m_nCols + 1]->ShowWindow(SW_SHOW); |
| | | |
| | | m_staticControls[row * m_nCols + 2]->SetWindowText(CString(data.inputDescription.c_str())); |
| | | m_staticControls[row * m_nCols + 2]->ShowWindow(SW_SHOW); |
| | | |
| | | m_staticControls[row * m_nCols + 3]->SetWindowText(_T("OFF")); |
| | | m_staticControls[row * m_nCols + 3]->ShowWindow(SW_SHOW); |
| | | m_staticControls[row * m_nCols + 3]->SetBkColor(RGB(255, 0, 0)); |
| | | |
| | | m_staticControls[row * m_nCols + 4]->SetWindowText(CString(data.outputAddress.c_str())); |
| | | m_staticControls[row * m_nCols + 4]->ShowWindow(SW_SHOW); |
| | | |
| | | m_staticControls[row * m_nCols + 5]->SetWindowText(CString(data.outputDescription.c_str())); |
| | | m_staticControls[row * m_nCols + 5]->ShowWindow(SW_SHOW); |
| | | } |
| | | else { |
| | | // éèè¿ä¸è¡çæææ§ä»¶ |
| | | for (int col = 0; col < m_nCols; ++col) { |
| | | m_staticControls[row * m_nCols + col]->ShowWindow(SW_HIDE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | UpdatePageInfo(); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::ClearDynamicControls() |
| | | { |
| | | for (auto* pStatic : m_staticControls) { |
| | | if (pStatic) { |
| | | pStatic->DestroyWindow(); |
| | | delete pStatic; |
| | | } |
| | | } |
| | | m_staticControls.clear(); |
| | | } |
| | | |
| | | bool CIOMonitoringDlg::ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr) |
| | | { |
| | | if (address.GetLength() < 2) { |
| | | return false; |
| | | } |
| | | |
| | | // æåç»ä»¶ç±»åï¼ç¬¬ä¸ä¸ªåç¬¦ï¼ |
| | | TCHAR componentChar = address[0]; |
| | | switch (componentChar) { |
| | | case 'D': |
| | | component = MC::SOFT_COMPONENT::D; |
| | | break; |
| | | case 'M': |
| | | component = MC::SOFT_COMPONENT::M; |
| | | break; |
| | | case 'X': |
| | | component = MC::SOFT_COMPONENT::X; |
| | | break; |
| | | case 'Y': |
| | | component = MC::SOFT_COMPONENT::Y; |
| | | break; |
| | | default: |
| | | return false; |
| | | } |
| | | |
| | | CString hexAddress = address.Mid(1); |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | void CIOMonitoringDlg::UpdatePLCStates() |
| | | { |
| | | // 示ä¾ï¼ä» PLC è·åå¼ï¼è¿éç¨éæºå¼æ¨¡æ |
| | | //for (size_t i = 0; i < m_inputPLCAddresses.size(); ++i) { |
| | | // // 模æè·åè¾å
¥ç¶æ |
| | | // bool inputState = (rand() % 2 == 0); // å¶å°ä¸º true/false |
| | | // auto* inputControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 0]); |
| | | // inputControl->SetBkColor(inputState ? RGB(0, 255, 0) : RGB(255, 0, 0)); |
| | | // inputControl->SetText(inputState ? _T("ON") : _T("OFF")); |
| | | //} |
| | | |
| | | //for (size_t i = 0; i < m_outputPLCAddresses.size(); ++i) { |
| | | // // 模æè·åè¾åºç¶æ |
| | | // bool outputState = (rand() % 2 == 0); // å¶å°ä¸º true/false |
| | | // auto* outputControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 3]); |
| | | // outputControl->SetBkColor(outputState ? RGB(0, 255, 0) : RGB(255, 0, 0)); |
| | | // outputControl->SetText(outputState ? _T("ON") : _T("OFF")); |
| | | //} |
| | | |
| | | // è¾å
¥å°åç读å |
| | | if (!m_inputPLCAddresses.empty()) { |
| | | // è·åèµ·å§å°ååé¿åº¦ |
| | | CString startAddressStr = m_inputPLCAddresses.front(); |
| | | CString endAddressStr = m_inputPLCAddresses.back(); |
| | | MC::SOFT_COMPONENT component; |
| | | int startAddress, endAddress; |
| | | |
| | | // è§£æèµ·å§åç»æå°å |
| | | if (ParsePLCAddress(startAddressStr, component, startAddress) && |
| | | ParsePLCAddress(endAddressStr, component, endAddress)) { |
| | | int inputSize = endAddress - startAddress + 1; |
| | | |
| | | // åè°å¤çè¾å
¥æ°æ® |
| | | auto funOnReadInput = [this, startAddress](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) { |
| | | if (nDataSize == (unsigned int)(m_inputPLCAddresses.size()) && flag == 0) { |
| | | for (size_t i = 0; i < m_inputPLCAddresses.size(); ++i) { |
| | | int offset = i; |
| | | int value = CToolUnits::toInt16(&pData[offset]); |
| | | |
| | | auto* inputControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 0]); // 第 0 å |
| | | inputControl->SetBkColor(value ? RGB(0, 255, 0) : RGB(255, 0, 0)); // æ´æ°èæ¯é¢è² |
| | | inputControl->SetText(value ? _T("ON") : _T("OFF")); // æ´æ°ææ¬ |
| | | } |
| | | } |
| | | }; |
| | | |
| | | // 读åè¾å
¥æ°æ® |
| | | m_pPLC->readData(component, startAddress, inputSize, funOnReadInput); |
| | | } |
| | | } |
| | | |
| | | // è¾åºå°åç读å |
| | | if (!m_outputPLCAddresses.empty()) { |
| | | // è·åèµ·å§å°ååé¿åº¦ |
| | | CString startAddressStr = m_outputPLCAddresses.front(); |
| | | CString endAddressStr = m_outputPLCAddresses.back(); |
| | | MC::SOFT_COMPONENT component; |
| | | int startAddress, endAddress; |
| | | |
| | | // è§£æèµ·å§åç»æå°å |
| | | if (ParsePLCAddress(startAddressStr, component, startAddress) && |
| | | ParsePLCAddress(endAddressStr, component, endAddress)) { |
| | | int outputSize = endAddress - startAddress + 1; |
| | | |
| | | // åè°å¤çè¾åºæ°æ® |
| | | auto funOnReadOutput = [this, startAddress](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) { |
| | | if (nDataSize == (unsigned int)(m_outputPLCAddresses.size()) && flag == 0) { |
| | | for (size_t i = 0; i < m_outputPLCAddresses.size(); ++i) { |
| | | int offset = i; |
| | | int value = CToolUnits::toInt16(&pData[offset]); |
| | | |
| | | auto* outputControl = static_cast<CBLLabel*>(m_staticControls[i * m_nCols + 3]); // 第 3 å |
| | | outputControl->SetBkColor(value ? RGB(0, 255, 0) : RGB(255, 0, 0)); // æ´æ°èæ¯é¢è² |
| | | outputControl->SetText(value ? _T("ON") : _T("OFF")); // æ´æ°ææ¬ |
| | | } |
| | | } |
| | | }; |
| | | |
| | | // 读åè¾åºæ°æ® |
| | | m_pPLC->readData(component, startAddress, outputSize, funOnReadOutput); |
| | | } |
| | | } |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CIOMonitoringDlg, CDialogEx) |
| | | ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CIOMonitoringDlg::OnBnClickedButtonPrevPage) |
| | | ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CIOMonitoringDlg::OnBnClickedButtonNextPage) |
| | | ON_WM_SIZE() |
| | | ON_WM_TIMER() |
| | | ON_WM_CLOSE() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CIOMonitoringDlg æ¶æ¯å¤çç¨åº |
| | | |
| | | |
| | | BOOL CIOMonitoringDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | CRect screenRect, dlgRect, clientRect; |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // åå§åé»è®¤åä½ |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåææåæ§ä»¶ï¼è®°å½åå§ä½ç½®å¹¶è®¾ç½®é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // è®°å½æ§ä»¶åå§å¸å± |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | // 设置é»è®¤åä½ |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | | |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | CreateDynamicControls(); |
| | | DisplayCurrentPage(); |
| | | |
| | | SetTimer(TIMER_READ_PLC_DATA, 500, nullptr); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | void CIOMonitoringDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // éåå¯¹è¯æ¡ä¸çæææ§ä»¶ |
| | | AdjustControls(dScaleX, dScaleY); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::OnBnClickedButtonPrevPage() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | if (m_nCurrentPage > 1) { |
| | | --m_nCurrentPage; |
| | | DisplayCurrentPage(); |
| | | } |
| | | else { |
| | | AfxMessageBox(_T("å·²ç»æ¯ç¬¬ä¸é¡µï¼")); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::OnBnClickedButtonNextPage() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | if (m_nCurrentPage < m_nTotalPages) { |
| | | ++m_nCurrentPage; |
| | | DisplayCurrentPage(); |
| | | } |
| | | else { |
| | | AfxMessageBox(_T("å·²ç»æ¯æåä¸é¡µï¼")); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | if (TIMER_READ_PLC_DATA == nIDEvent) { |
| | | ASSERT(m_pPLC); |
| | | UpdatePLCStates(); |
| | | Sleep(100); |
| | | } |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | } |
| | | |
| | | void CIOMonitoringDlg::OnClose() |
| | | { |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | KillTimer(TIMER_READ_PLC_DATA); |
| | | CDialogEx::OnClose(); |
| | | } |