// CComponentData1Dlg.cpp: 实现文件 // #include "stdafx.h" #include "BondEq.h" #include "CRemoteEqView.h" #include "afxdialogex.h" #include "Log.h" #include "ToolUnits.h" #include "Common.h" // CComponentData1Dlg 对话框 IMPLEMENT_DYNAMIC(CRemoteEqView, CBaseView) CRemoteEqView::CRemoteEqView(CWnd* pParent /*=nullptr*/) : CBaseView(IDD_COMPONENT_REMOTE_EQ, pParent) { m_pObserver = nullptr; m_crBkgnd = REMOTE_EQ_VIEW_BACKGROUND; m_hbrBkgnd = nullptr; } CRemoteEqView::~CRemoteEqView() { for (CRemoteEqUnitView* pView : m_tabViews) { if (pView) { pView->DestroyWindow(); delete pView; } } m_tabViews.clear(); } void CRemoteEqView::DoDataExchange(CDataExchange* pDX) { CBaseView::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CRemoteEqView, CBaseView) ON_WM_CTLCOLOR() ON_WM_DESTROY() ON_WM_SIZE() ON_WM_TIMER() ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_UNITS, &CRemoteEqView::OnSelchangeUnitTab) END_MESSAGE_MAP() // CComponentData1Dlg 消息处理程序 void CRemoteEqView::InitRxWindows() { /* code */ // 订阅数据 IRxWindows* pRxWindows = RX_GetRxWindows(); if (m_pObserver == NULL) { m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void { // onNext pAny->addRef(); int code = pAny->getCode(); pAny->release(); }, [&]() -> void { // onComplete }, [&](IThrowable* pThrowable) -> void { // onErrorm pThrowable->printf(); }); theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread()) ->subscribe(m_pObserver); } } BOOL CRemoteEqView::OnInitDialog() { CBaseView::OnInitDialog(); SetTimer(1, 200, NULL); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } HBRUSH CRemoteEqView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC) { pDC->SetBkColor(m_crBkgnd); } if (m_hbrBkgnd == nullptr) { m_hbrBkgnd = CreateSolidBrush(m_crBkgnd); } return m_hbrBkgnd; } void CRemoteEqView::OnDestroy() { CBaseView::OnDestroy(); if (m_hbrBkgnd != nullptr) { ::DeleteObject(m_hbrBkgnd); } ASSERT(m_pObserver != NULL); m_pObserver->unsubscribe(); m_pObserver = NULL; } void CRemoteEqView::OnSize(UINT nType, int cx, int cy) { CBaseView::OnSize(nType, cx, cy); } void CRemoteEqView::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (1 == nIDEvent) { KillTimer(1); InitRxWindows(); LoadData(); } CBaseView::OnTimer(nIDEvent); } void CRemoteEqView::LoadData() { BEQ::IRemoteEquipment* pEquipment = (BEQ::IRemoteEquipment*)GetContext(); if (pEquipment == nullptr) { return; } CTabCtrl* pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TAB_UNITS); const char** names = pEquipment->getAllUnitNames(); AddUnitTabs(*pTabCtrl, names); if (m_tabViews.size() > 0 && !m_tabViews.empty()) { m_tabViews[0]->ShowWindow(SW_SHOW); } } void CRemoteEqView::Resize() { int y = 12; int x = 0; CRect rcClient, rcItem; CWnd* pItem; GetClientRect(&rcClient); } void CRemoteEqView::AddUnitTabs(CTabCtrl& tabCtrl, const char** names) { BEQ::IRemoteEquipment* pEquipment = (BEQ::IRemoteEquipment*)GetContext(); if (pEquipment == nullptr) { return; } int tabIndex = 0; while (names[tabIndex] != nullptr) { BEQ::IUnit* pUnit = pEquipment->getUnit(names[tabIndex]); if (pUnit == nullptr) { ++tabIndex; continue; } CString tabText(names[tabIndex]); tabCtrl.InsertItem(tabIndex, tabText); CRemoteEqUnitView* pView = new CRemoteEqUnitView(); if (pView->Create(IDD_COMPONENT_REMOTE_EQ_UNIT, &tabCtrl)) { CRect rect; tabCtrl.GetClientRect(&rect); tabCtrl.AdjustRect(FALSE, &rect); rect.DeflateRect(10, 10); pView->MoveWindow(rect); pView->ShowWindow(SW_HIDE); pView->SetContext(pUnit); m_tabViews.push_back(pView); } ++tabIndex; } } void CRemoteEqView::OnSelchangeUnitTab(NMHDR* pNMHDR, LRESULT* pResult) { CTabCtrl* pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TAB_UNITS); int selectedIndex = pTabCtrl->GetCurSel(); for (CRemoteEqUnitView* pView : m_tabViews) { pView->ShowWindow(SW_HIDE); } if (selectedIndex >= 0 && selectedIndex < m_tabViews.size()) { m_tabViews[selectedIndex]->ShowWindow(SW_SHOW); } *pResult = 0; }