LAPTOP-T815PCOQ\25526
2024-11-28 fc8a07f476648f82abf9934483b04cfee0161e4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "afxdialogex.h"
#include "IOManager.h"
#include "BLLabel.h"
 
 
// CIOMonitoringDlg 对话框
 
class CIOMonitoringDlg : public CDialogEx
{
    DECLARE_DYNAMIC(CIOMonitoringDlg)
 
public:
    CIOMonitoringDlg(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CIOMonitoringDlg();
    void SetIOManager(const std::string& machineName); // 设置 IOManager 和机器名
 
// 对话框数据
#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();    // 动态创建控件
    void CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder = false, TextAlign alignment = AlignLeft, std::function<void()> clickCallback = nullptr); // 创建静态控件
    void DisplayCurrentPage();        // 显示当前页数据
    void ClearDynamicControls();    // 清除动态创建的控件
    void UpdatePLCStates();            // 定时器更新状态的方法
 
private:
    int m_nInitialWidth;
    int m_nInitialHeight;
    int m_nCurrentPage; // 当前页
    int m_nTotalPages;    // 总页数
    int m_nRowsPerPage; // 每页显示的行数
    int m_nCols;        // 每行的控件组数
    std::string m_machineName; // 当前机器名
    std::map<int, CFont*> m_mapFonts;        // 字体映射
    std::map<int, CRect> m_mapCtrlLayouts;    // 控件布局映射
    std::vector<IOData> m_displayData;        // 当前显示的数据
    std::vector<CString> m_inputPLCAddresses;  // 存储 1 列 PLC 地址
    std::vector<CString> m_outputPLCAddresses; // 存储 4 列 PLC 地址
 
private:
    CStatic m_staticPageNum;
    std::vector<CBLLabel*> 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 void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnClose();
};