From cb4de5ef9411ce1912c6f7d6cd85506c6f619f3c Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期三, 10 十二月 2025 15:08:55 +0800
Subject: [PATCH] 1.属性页增加按钮。
---
SourceCode/Bond/Servo/CHMPropertyDlg.cpp | 84 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/SourceCode/Bond/Servo/CHMPropertyDlg.cpp b/SourceCode/Bond/Servo/CHMPropertyDlg.cpp
index 2542fca..e6bba3e 100644
--- a/SourceCode/Bond/Servo/CHMPropertyDlg.cpp
+++ b/SourceCode/Bond/Servo/CHMPropertyDlg.cpp
@@ -5,7 +5,6 @@
#include "Servo.h"
#include "CHMPropertyDlg.h"
#include "afxdialogex.h"
-#include "HmTab.h"
// CEquipmentDlg 瀵硅瘽妗�
@@ -19,6 +18,7 @@
m_hbrBkgnd = nullptr;
m_nWndWidth = 0;
m_nWndHeight = 0;
+ m_pTab = nullptr;
}
CHMPropertyDlg::CHMPropertyDlg(const char* pszTitle, int width, int height)
@@ -29,6 +29,7 @@
m_nWndWidth = width;
m_nWndHeight = height;
m_strTitle = pszTitle;
+ m_pTab = nullptr;
}
CHMPropertyDlg::~CHMPropertyDlg()
@@ -74,12 +75,13 @@
// Tab
CString strTitle;
- CHmTab* m_pTab = CHmTab::Hook(GetDlgItem(IDC_TAB1)->m_hWnd);
+ m_pTab = CHmTab::Hook(GetDlgItem(IDC_TAB1)->m_hWnd);
m_pTab->SetPaddingLeft(20);
m_pTab->SetItemMarginLeft(18);
for (int i = 0; i < m_pages.size(); i++) {
m_pages[i]->SetParent(this);
m_pages[i]->GetWindowText(strTitle);
+ m_pages[i]->OnCreateBtns();
m_pTab->AddItem(strTitle, i == m_pages.size() - 1);
}
m_pTab->SetCurSel(0);
@@ -125,7 +127,7 @@
void CHMPropertyDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
- if (GetDlgItem(IDC_TAB1) == nullptr) return;
+ if (m_pTab == nullptr) return;
Resize();
}
@@ -157,8 +159,36 @@
pItem->GetWindowRect(&rcItem);
pItem->MoveWindow(x2 - rcItem.Width(), y2 - rcItem.Height(),
rcItem.Width(), rcItem.Height());
- y2 -= rcItem.Height();
- y2 -= 12;
+ y2 -= rcItem.Height() + 12;
+
+ // 褰撳墠瀛愰〉鎸夐挳锛堝鏋滄湁锛�
+ int btnY = y2 - rcItem.Height(); // 淇濇寔涓庡簲鐢ㄦ寜閽悓楂�
+ int btnX = 12;
+ int curIndex = (m_pTab != nullptr) ? m_pTab->GetCurSel() : 0;
+ if (curIndex >= 0 && curIndex < (int)m_pages.size()) {
+ auto& btnMap = m_pages[curIndex]->getBtns();
+ // 鎸� BTN_ORDER 鎺掑簭
+ std::vector<std::pair<int, CButton*>> ordered;
+ for (auto& kv : btnMap) {
+ CButton* btn = kv.second;
+ if (btn == nullptr || !::IsWindow(btn->GetSafeHwnd())) continue;
+ int order = (int)(INT_PTR)::GetProp(btn->GetSafeHwnd(), _T("BTN_ORDER"));
+ ordered.emplace_back(order, btn);
+ }
+ std::sort(ordered.begin(), ordered.end(), [](const auto& a, const auto& b) {
+ return a.first < b.first;
+ });
+ for (auto& item : ordered) {
+ CButton* btn = item.second;
+ CRect rcBtn;
+ btn->GetWindowRect(&rcBtn);
+ if (rcBtn.Width() <= 0 || rcBtn.Height() <= 0) {
+ rcBtn.SetRect(0, 0, 80, 28);
+ }
+ btn->MoveWindow(btnX, btnY, rcBtn.Width(), rcBtn.Height());
+ btnX += rcBtn.Width() + 8;
+ }
+ }
// 鍒嗛殧绾�
pItem = GetDlgItem(IDC_LINE1);
@@ -185,6 +215,50 @@
for (int i = 0; i < m_pages.size(); i++) {
m_pages[i]->ShowWindow(i == index ? SW_SHOW : SW_HIDE);
}
+
+ // 闅愯棌鎵�鏈夐〉闈㈢殑鎸夐挳
+ for (auto page : m_pages) {
+ for (auto& kv : page->getBtns()) {
+ CButton* btn = kv.second;
+ if (btn != nullptr && ::IsWindow(btn->GetSafeHwnd())) {
+ btn->ShowWindow(SW_HIDE);
+ }
+ }
+ }
+
+ // 鍒涘缓骞舵樉绀哄綋鍓嶉〉闈㈢殑鎸夐挳
+ auto& btns = m_pages[index]->getBtns();
+ if (!btns.empty()) {
+ CRect rcClient;
+ GetClientRect(&rcClient);
+ const int margin = 12;
+ const int spacing = 8;
+ int x = margin;
+ int y = rcClient.bottom - 40; // 棰勭暀搴曢儴鍖哄煙
+
+ // 鎸� BTN_ORDER 鎺掑簭
+ std::vector<std::pair<int, CButton*>> ordered;
+ for (auto& kv : btns) {
+ CButton* btn = kv.second;
+ if (btn == nullptr || !::IsWindow(btn->GetSafeHwnd())) continue;
+ int order = (int)(INT_PTR)::GetProp(btn->GetSafeHwnd(), _T("BTN_ORDER"));
+ ordered.emplace_back(order, btn);
+ }
+ std::sort(ordered.begin(), ordered.end(), [](const auto& a, const auto& b) {
+ return a.first < b.first;
+ });
+ for (auto& item : ordered) {
+ CButton* btn = item.second;
+ CRect rc;
+ btn->GetWindowRect(&rc);
+ if (rc.Width() <= 0 || rc.Height() <= 0) {
+ rc.SetRect(0, 0, 80, 28);
+ }
+ btn->MoveWindow(x, y, rc.Width(), rc.Height());
+ btn->ShowWindow(SW_SHOW);
+ x += rc.Width() + spacing;
+ }
+ }
}
void CHMPropertyDlg::SetWindowSize(int width, int height)
--
Gitblit v1.9.3