LAPTOP-SNT8I5JK\Boounion
2025-06-20 7d9ce4a2ba0a6a338797f30bdd056768a740605c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// PortConfigurationDlg.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "PortConfigurationDlg.h"
#include "NewCellTypes/GridCellCheck.h"
#include "NewCellTypes/GridCellCombo.h"
#include "NewCellTypes/GridCellNumeric.h"
 
 
// CPortConfigurationDlg 对话框
 
IMPLEMENT_DYNAMIC(CPortConfigurationDlg, CDialogEx)
 
CPortConfigurationDlg::CPortConfigurationDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_PORT_CONFIGURATION, pParent)
{
 
}
 
CPortConfigurationDlg::~CPortConfigurationDlg()
{
}
 
void CPortConfigurationDlg::InitGrid()
{
    if (m_wndGrid.GetSafeHwnd() == NULL) {
        return;
    }
 
    const int nCols = 3;
    const int nFixRows = 1;
    const int nRows = 9;
 
    int nColIdx = 0;
    m_wndGrid.DeleteAllItems();
    m_wndGrid.SetVirtualMode(FALSE);
 
    // 设置样式颜色
    m_wndGrid.GetDefaultCell(TRUE, FALSE)->SetBackClr(g_nGridFixCellColor);
    m_wndGrid.GetDefaultCell(FALSE, TRUE)->SetBackClr(g_nGridFixCellColor);
    m_wndGrid.GetDefaultCell(FALSE, FALSE)->SetBackClr(g_nGridCellColor);
    m_wndGrid.SetFixedTextColor(g_nGridFixFontColor);
 
    // 行列数量
    m_wndGrid.SetRowCount(nRows);
    m_wndGrid.SetColumnCount(nCols);
    m_wndGrid.SetFixedRowCount(nFixRows);
    m_wndGrid.SetFixedColumnCount(0);
 
    // 设置列宽
    m_wndGrid.SetColumnWidth(nColIdx, 50);
    m_wndGrid.SetItemText(0, nColIdx++, _T("Slot ID"));
    m_wndGrid.SetColumnWidth(nColIdx, 150);
    m_wndGrid.SetItemText(0, nColIdx++, _T("EQ Recipe"));
    m_wndGrid.SetColumnWidth(nColIdx, 150);
    m_wndGrid.SetItemText(0, nColIdx++, _T("Panel ID"));
    m_wndGrid.SetColumnWidth(nColIdx, 60);
    m_wndGrid.SetItemText(0, nColIdx++, _T("启用"));
 
    // 设置行为样式
    m_wndGrid.SetFixedRowSelection(FALSE);
    m_wndGrid.SetFixedColumnSelection(FALSE);
    m_wndGrid.SetEditable(TRUE);
    m_wndGrid.SetRowResize(FALSE);
    m_wndGrid.SetColumnResize(TRUE);
    m_wndGrid.SetListMode(TRUE);
    m_wndGrid.EnableSelection(TRUE);
    m_wndGrid.SetSingleRowSelection(TRUE);
    m_wndGrid.ExpandColumnsToFit(TRUE);
    m_wndGrid.ExpandLastColumn();
 
    // 自动计算并设置每行高度
    CRect rcClient;
    m_wndGrid.GetClientRect(&rcClient);
    int nAvailableHeight = rcClient.Height();
    int nEachRowHeight = max(24, nAvailableHeight / nRows);
 
    for (int i = 0; i < nRows; ++i) {
        m_wndGrid.SetRowHeight(i, nEachRowHeight);
    }
 
    FillGrid();
}
 
void CPortConfigurationDlg::FillGrid()
{
    //CStringArray recipeOptions;
    //recipeOptions.Add(_T("Recipe A"));
    //recipeOptions.Add(_T("Recipe B"));
    //recipeOptions.Add(_T("Recipe C"));
 
    for (int i = 1; i < 9; ++i) {
        CString strIndex;
        strIndex.Format(_T("%d"), i);
        m_wndGrid.SetItemText(i, 0, strIndex);
        m_wndGrid.SetItemState(i, 0, GVIS_READONLY);
 
        // EQ Recipe - ComboBox
        //if (m_wndGrid.SetCellType(i, 1, RUNTIME_CLASS(CGridCellCombo))) {
        //    CGridCellCombo* pCell = static_cast<CGridCellCombo*>(m_wndGrid.GetCell(i, 1));
        //    pCell->SetOptions(recipeOptions);
        //    pCell->SetStyle(CBS_DROPDOWNLIST);
        //}
        //m_wndGrid.SetItemText(i, 1, recipeOptions[0]);
 
        // Panel ID - 可编辑
        m_wndGrid.SetItemText(i, 1, _T(""));
 
        // Checkbox
        m_wndGrid.SetCellType(i, 2, RUNTIME_CLASS(CGridCellCheck));
        CGridCellCheck* pCheck = static_cast<CGridCellCheck*>(m_wndGrid.GetCell(i, 2));
        if (pCheck) {
            pCheck->SetCheck(FALSE);
        }
    }
 
    m_wndGrid.Invalidate();
    m_wndGrid.UpdateWindow();
}
 
void CPortConfigurationDlg::DoDataExchange(CDataExchange* pDX)
{
    DDX_Control(pDX, IDC_GRID_PANEL_RECIPE, m_wndGrid);
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CPortConfigurationDlg, CDialogEx)
END_MESSAGE_MAP()
 
 
// CPortConfigurationDlg 消息处理程序
 
BOOL CPortConfigurationDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // TODO:  在此添加额外的初始化
    InitGrid();
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
}