#pragma once #include "afxdialogex.h" #include "IOManager.h" #include "BLLabel.h" #include "PLC.h" // CIOMonitoringDlg 对话框 class CIOMonitoringDlg : public CDialogEx { DECLARE_DYNAMIC(CIOMonitoringDlg) public: CIOMonitoringDlg(CWnd* pParent = nullptr); // 标准构造函数 virtual ~CIOMonitoringDlg(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOG_IO_MONITORING }; #endif private: CFont* GetOrCreateFont(int nFontSize); // 获取或创建字体 void SetDefaultFont(); // 设置默认字体 void AdjustControls(float dScaleX, float dScaleY); // 调整控件大小 void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); // 调整控件字体大小 void UpdatePageInfo(); // 更新分页信息 void CreateDynamicControls(); // 动态创建控件 CWnd* CreateStaticControl(UINT id, int x, int y, int width, int height, const CString& text, bool hasBorder = false, TextAlign alignment = AlignLeft, std::function clickCallback = nullptr); // 创建静态控件 CWnd* GetStaticControl(UINT id); // 获取静态控件 CString& GetStaticControlAddrText(UINT id, CString& strAddr); // 获取静态控件地址文本 void DisplayCurrentPage(); // 显示当前页数据 void ClearDynamicControls(); // 清除动态创建的控件 bool ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr); // 解析 PLC 地址 bool GeneratePLCAddress(MC::SOFT_COMPONENT component, int addr, CString& address, bool bHexFormat = false); // 生成 PLC 地址 void ReadPLCData(MC::SOFT_COMPONENT softComponent, int startAddr, int endAddr, std::function callback); // 读取 PLC 数据 void ReadPLCStates(); // 定时器读PLC void UpdatePLCStatesToUI(); // 定时器更新状态的方法 private: CPLC* m_pPLC; int m_nInitialWidth; int m_nInitialHeight; int m_nCurrentPage; // 当前页 int m_nTotalPages; // 总页数 int m_nRowsPerPage; // 每页显示的行数 int m_nCols; // 每行的控件组数 std::map m_mapFonts; // 字体映射 std::map m_mapCtrlLayouts; // 控件布局映射 std::vector m_displayData; // 当前显示的数据 std::vector m_inputStates; // 输入状态 std::vector m_outputStates; // 输出状态 std::vector m_inputPLCAddresses; // 存储 1 列 PLC 地址 std::vector m_outputPLCAddresses; // 存储 4 列 PLC 地址 private: CStatic m_staticPageNum; std::vector m_staticControls; // 动态创建的静态控件 protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: virtual BOOL OnInitDialog(); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnBnClickedButtonPrevPage(); afx_msg void OnBnClickedButtonNextPage(); afx_msg LRESULT OnIoClicked(WPARAM wParam, LPARAM lParam); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnClose(); };