| | |
| | | { |
| | | m_crBkgnd = PAGE_PLC_LIST_BACKGROUND; |
| | | m_hbrBkgnd = nullptr; |
| | | m_pObserver = nullptr; |
| | | } |
| | | |
| | | CPagePlcList::~CPagePlcList() |
| | |
| | | // CPagePlcList 消息处理程序 |
| | | |
| | | |
| | | void CPagePlcList::InitRxWindows() |
| | | { |
| | | /* code */ |
| | | // 订阅数据 |
| | | IRxWindows* pRxWindows = RX_GetRxWindows(); |
| | | pRxWindows->enableLog(5); |
| | | if (m_pObserver == NULL) { |
| | | m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void { |
| | | // onNext |
| | | pAny->addRef(); |
| | | int code = pAny->getCode(); |
| | | if (RX_CODE_ADD_PLC == code) { |
| | | CPLC* pPlc; |
| | | if (pAny->getPtrValue("ptr", (void*&)pPlc)) { |
| | | HTREEITEM hItem = m_treeCtrl.InsertItem(pPlc->getName().c_str(), nullptr, nullptr); |
| | | m_treeCtrl.SetItemData(hItem, (DWORD_PTR)pPlc); |
| | | } |
| | | } |
| | | else if (RX_CODE_REMOVE_PLC == code) { |
| | | CPLC* pPlc; |
| | | if (pAny->getPtrValue("ptr", (void*&)pPlc)) { |
| | | HTREEITEM hItem = FindItem(pPlc); |
| | | if (hItem != nullptr) { |
| | | m_treeCtrl.DeleteItem(hItem); |
| | | } |
| | | } |
| | | } |
| | | |
| | | pAny->release(); |
| | | }, [&]() -> void { |
| | | // onComplete |
| | | }, [&](IThrowable* pThrowable) -> void { |
| | | // onErrorm |
| | | pThrowable->printf(); |
| | | }); |
| | | |
| | | theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread()) |
| | | ->subscribe(m_pObserver); |
| | | } |
| | | } |
| | | |
| | | BOOL CPagePlcList::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | InitRxWindows(); |
| | | |
| | | |
| | | m_treeCtrl.SetBkColor(PAGE_PLC_LIST_BACKGROUND); |
| | |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | if (m_pObserver != nullptr) { |
| | | m_pObserver->unsubscribe(); |
| | | m_pObserver = NULL; |
| | | } |
| | | } |
| | | |
| | | void CPagePlcList::OnSize(UINT nType, int cx, int cy) |
| | |
| | | |
| | | void CPagePlcList::ReadPLCList() |
| | | { |
| | | m_treeCtrl.InsertItem("PLC1", nullptr, nullptr); |
| | | m_treeCtrl.InsertItem("PLC2", nullptr, nullptr); |
| | | //m_treeCtrl.InsertItem("PLC1", nullptr, nullptr); |
| | | //m_treeCtrl.InsertItem("PLC2", nullptr, nullptr); |
| | | } |
| | | |
| | | BOOL CPagePlcList::PreTranslateMessage(MSG* pMsg) |
| | |
| | | |
| | | return CDialogEx::PreTranslateMessage(pMsg); |
| | | } |
| | | |
| | | HTREEITEM CPagePlcList::FindItem(CPLC* pPlc) |
| | | { |
| | | |
| | | HTREEITEM item = m_treeCtrl.GetChildItem(nullptr); |
| | | while (item != nullptr) { |
| | | item = m_treeCtrl.GetNextItem(item, TVGN_NEXT); |
| | | if (m_treeCtrl.GetItemData(item) == (DWORD_PTR)pPlc) { |
| | | return item; |
| | | } |
| | | } |
| | | |
| | | return nullptr; |
| | | } |