From c3f30f69f3da4e4ed018ba0307e64e327915d4ca Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 22 七月 2025 13:41:24 +0800
Subject: [PATCH] 1. PPID配方绑定界面优化,动态控件获取窗口画笔
---
SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp | 154 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 108 insertions(+), 46 deletions(-)
diff --git a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
index 4d3440d..22ef3ca 100644
--- a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
+++ b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
@@ -67,73 +67,135 @@
{
CDialogEx::OnInitDialog();
- // TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+ // 璁剧疆瀵硅瘽妗嗘爣棰�
+ SetWindowText(m_recipe.vecDeviceList.empty() ? _T("鏂板缓閰嶆柟") : _T("缂栬緫閰嶆柟"));
+
+ if (m_font.m_hObject == NULL) {
+ // 鑾峰彇瀵硅瘽妗嗙殑瀛椾綋
+ CFont* pDlgFont = GetFont();
+ LOGFONT lf;
+ if (pDlgFont && pDlgFont->GetLogFont(&lf)) {
+ m_font.CreateFontIndirect(&lf);
+ }
+ }
+
+ // 璁$畻x璧峰鍧愭爣
+ CWnd* pWndDesc = GetDlgItem(IDC_STATIC_DESC);
+ CRect rDesc;
+ int nYStart = 0;
+ int nXStart = 0;
+ int nTotalControlWidth = 340; // 榛樿鍏滃簳
+ if (pWndDesc) {
+ pWndDesc->GetWindowRect(&rDesc);
+ ScreenToClient(&rDesc);
+ nXStart = rDesc.left;
+ }
+ else {
+ nXStart = 30;
+ }
+
+ // 璁$畻x璧峰鍧愭爣
+ pWndDesc = GetDlgItem(IDC_EDIT_DESC);
+ if (pWndDesc) {
+ pWndDesc->GetWindowRect(&rDesc);
+ ScreenToClient(&rDesc);
+ nYStart = rDesc.bottom + 20;
+ }
+ else {
+ nYStart = 30;
+ }
+
+ // 淇濊瘉姣忔杩涙潵閮芥竻绌�
+ for (auto& ctrl : m_vecDevices) {
+ if (ctrl.editDeviceID) {
+ delete ctrl.editDeviceID;
+ ctrl.editDeviceID = nullptr;
+ }
+
+ if (ctrl.editDeviceName) {
+ delete ctrl.editDeviceName;
+ ctrl.editDeviceName = nullptr;
+ }
+
+ if (ctrl.comboRecipeID) {
+ delete ctrl.comboRecipeID;
+ ctrl.comboRecipeID = nullptr;
+ }
+ }
+ m_vecDevices.clear();
+
+ // 鍒涘缓鎺т欢锛堜笉绠℃柊寤鸿繕鏄紪杈戯紝閮藉厛鍒涘缓濂斤級
+ CRect rClient;
+ GetClientRect(&rClient);
+ nTotalControlWidth = (rClient.Width() - nXStart * 2);
+ const int nRowHeight = 30;
+ const int nRowCount = static_cast<int>(g_vecBindDevices.size());
+ for (int i = 0; i < nRowCount; ++i) {
+ int y = nYStart + i * nRowHeight;
+ const auto& meta = g_vecBindDevices[i];
+
+ CEdit* pEditID = new CEdit();
+ pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(nXStart, y, nXStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i);
+
+ CEdit* pEditName = new CEdit();
+ pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(nXStart + 110, y, nXStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i);
+
+ CComboBox* pCombo = new CComboBox();
+ pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(nXStart + 220, y, nXStart + nTotalControlWidth, y + 25), this, IDC_COMBO_RECIPEID_BASE + i);
+
+ pEditID->SetFont(&m_font);
+ pEditName->SetFont(&m_font);
+ pCombo->SetFont(&m_font);
+
+ m_vecDevices.push_back({ pEditID, pEditName, pCombo });
+ }
+
+ // 濉厖鍐呭
if (m_recipe.vecDeviceList.empty()) {
- SetWindowText(_T("鏂板缓閰嶆柟"));
-
- // 璁剧疆鍥哄畾澶у皬锛堜緥濡� 600x400锛�
- SetWindowPos(nullptr, 0, 0, 600, 400, SWP_NOMOVE | SWP_NOZORDER);
-
- // 鍒涘缓鎺т欢
- const int totalControlWidth = 340;
- CRect clientRect;
- GetClientRect(&clientRect);
- int xStart = (clientRect.Width() - totalControlWidth) / 2;
-
- const int nRowHeight = 30;
- const int yStart = 30; // 椤堕儴璧峰楂樺害
-
- const int nRowCount = static_cast<int>(g_vecBindDevices.size());
+ // 鏂板缓妯″紡
for (int i = 0; i < nRowCount; ++i) {
- int y = yStart + i * nRowHeight;
const auto& meta = g_vecBindDevices[i];
-
- CEdit* pEditID = new CEdit();
- pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart, y, xStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i);
-
CString strID;
strID.Format(_T("%d"), meta.nDeviceID);
- pEditID->SetWindowText(strID);
- pEditID->SetReadOnly(TRUE); // 璁惧ID鍙
+ m_vecDevices[i].editDeviceID->SetWindowText(strID);
+ m_vecDevices[i].editDeviceID->SetReadOnly(TRUE);
- CEdit* pEditName = new CEdit();
- pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart + 110, y, xStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i);
- pEditName->SetWindowText(CA2T(meta.strDeviceName));
- pEditName->SetReadOnly(TRUE); // 璁惧鍚嶇О鍙
+ m_vecDevices[i].editDeviceName->SetWindowText(CA2T(meta.strDeviceName));
+ m_vecDevices[i].editDeviceName->SetReadOnly(TRUE);
- CComboBox* pCombo = new CComboBox();
- pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(xStart + 220, y, xStart + 340, y + 300), this, IDC_COMBO_RECIPEID_BASE + i);
-
- // 娣诲姞閫夐」鍒� ComboBox
- m_vecDevices.push_back({ pEditID, pEditName, pCombo });
+ // 杩欓噷浣犲彲浠ュ垵濮嬪寲 ComboBox 閫夐」锛屼緥濡傦細
+ // for (const auto& r : GetRecipeListForDevice(meta.nDeviceID)) {
+ // int idx = m_vecDevices[i].comboRecipeID->AddString(CA2T(r.strRecipeName));
+ // m_vecDevices[i].comboRecipeID->SetItemData(idx, r.nRecipeID);
+ // }
}
}
else {
- SetWindowText(_T("缂栬緫閰嶆柟"));
-
+ // 缂栬緫妯″紡
m_strPPID = CA2T(m_recipe.strPPID.c_str());
m_strDesc = CA2T(m_recipe.strDescription.c_str());
UpdateData(FALSE);
- // 璁剧疆璁惧琛屾暟鎹�
for (size_t i = 0; i < m_recipe.vecDeviceList.size() && i < m_vecDevices.size(); ++i) {
const DeviceRecipe& d = m_recipe.vecDeviceList[i];
CString str;
- // 璁剧疆璁惧ID鍜屽悕绉�
+ // 璁惧ID
str.Format(_T("%d"), d.nDeviceID);
m_vecDevices[i].editDeviceID->SetWindowText(str);
+ m_vecDevices[i].editDeviceID->SetReadOnly(TRUE);
- str.Format(_T("%s"), d.strDeviceName.c_str());
- m_vecDevices[i].editDeviceName->SetWindowText(str);
+ // 璁惧鍚嶇О
+ m_vecDevices[i].editDeviceName->SetWindowText(CA2T(d.strDeviceName.c_str()));
+ m_vecDevices[i].editDeviceName->SetReadOnly(TRUE);
- /*ComboBox閫夋嫨閰嶆柟ID锛屽悗闈㈤渶瑕佷慨鏀�****/
- //int nCount = m_vecDevices[i].comboRecipeID->GetCount();
- //for (int idx = 0; idx < nCount; ++idx) {
- // if ((int)m_vecDevices[i].comboRecipeID->GetItemData(idx) == d.nRecipeID) {
- // m_vecDevices[i].comboRecipeID->SetCurSel(idx);
- // break;
- // }
- //}
+ // ComboBox 閫夐」濉厖
+ // for (const auto& r : GetRecipeListForDevice(d.nDeviceID)) {
+ // int idx = m_vecDevices[i].comboRecipeID->AddString(CA2T(r.strRecipeName));
+ // m_vecDevices[i].comboRecipeID->SetItemData(idx, r.nRecipeID);
+ // // 榛樿閫変腑瀵瑰簲閰嶆柟ID
+ // if (r.nRecipeID == d.nRecipeID)
+ // m_vecDevices[i].comboRecipeID->SetCurSel(idx);
+ // }
}
}
--
Gitblit v1.9.3