| | |
| | | #include "Servo.h" |
| | | #include "CHMPropertyDlg.h" |
| | | #include "afxdialogex.h" |
| | | #include "HmTab.h" |
| | | #include <algorithm> |
| | | |
| | | |
| | | // CEquipmentDlg 对话框 |
| | |
| | | m_hbrBkgnd = nullptr; |
| | | m_nWndWidth = 0; |
| | | m_nWndHeight = 0; |
| | | m_pTab = nullptr; |
| | | } |
| | | |
| | | CHMPropertyDlg::CHMPropertyDlg(const char* pszTitle, int width, int height) |
| | |
| | | m_nWndWidth = width; |
| | | m_nWndHeight = height; |
| | | m_strTitle = pszTitle; |
| | | m_pTab = nullptr; |
| | | } |
| | | |
| | | CHMPropertyDlg::~CHMPropertyDlg() |
| | |
| | | |
| | | // 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); |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | pItem->GetWindowRect(&rcItem); |
| | | pItem->MoveWindow(x2 - rcItem.Width(), y2 - rcItem.Height(), |
| | | rcItem.Width(), rcItem.Height()); |
| | | y2 -= rcItem.Height(); |
| | | y2 -= 12; |
| | | |
| | | // 当前子页按钮(如果有) |
| | | int btnY = y2 - rcItem.Height(); |
| | | int btnX = 12; |
| | | y2 -= rcItem.Height() + 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); |
| | |
| | | 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) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | BOOL CHMPropertyDlg::OnCommand(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | UINT code = HIWORD(wParam); |
| | | HWND hCtrl = (HWND)lParam; |
| | | |
| | | if (code == BN_CLICKED && hCtrl != nullptr) { |
| | | for (auto page : m_pages) { |
| | | for (auto& kv : page->getBtns()) { |
| | | if (kv.second != nullptr && kv.second->GetSafeHwnd() == hCtrl) { |
| | | page->HandleBtnClick(hCtrl); |
| | | return TRUE; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return CDialogEx::OnCommand(wParam, lParam); |
| | | } |