From c2d22fc8efd988294ff4a34fd3e31a9743803964 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 08 一月 2025 11:02:16 +0800
Subject: [PATCH] 1.PLC View的加入,关闭,关联等;
---
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 132 insertions(+), 2 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
index 4ff72a9..dbd2ea0 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -7,6 +7,7 @@
#include "BoounionPLCDlg.h"
#include "afxdialogex.h"
#include "Common.h"
+#include "PlcView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -55,8 +56,10 @@
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pTopToolbar = nullptr;
+ m_pObserver = nullptr;
m_crBkgnd = APP_MAIN_DLG_BACKGROUND;
m_hbrBkgnd = nullptr;
+ m_pActiveView = nullptr;
}
void CBoounionPLCDlg::DoDataExchange(CDataExchange* pDX)
@@ -78,10 +81,53 @@
ON_COMMAND(ID_MENU_HELP_ABOUT, &CBoounionPLCDlg::OnMenuHelpAbout)
ON_WM_INITMENUPOPUP()
ON_MESSAGE(ID_MSG_TOOLBAR_BTN_CLICKED, &CBoounionPLCDlg::OnToolbarBtnClicked)
+ ON_MESSAGE(ID_MSG_VIEW_ACTIVE, &CBoounionPLCDlg::OnViewActive)
+ ON_MESSAGE(ID_MSG_BTN_CLICKED, &CBoounionPLCDlg::OnViewBtnClicked)
+ ON_MESSAGE(ID_MSG_BTN_MENU_ITEM, &CBoounionPLCDlg::OnViewBtnMenuItem)
END_MESSAGE_MAP()
// CBoounionPLCDlg 消息处理程序
+
+
+void CBoounionPLCDlg::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_SELECT_PLC == code) {
+ CPLC* pPlc;
+ if (pAny->getPtrValue("ptr", (void*&)pPlc)) {
+ ASSERT(m_pMainContainer != nullptr);
+ if (m_pActiveView == nullptr) {
+ m_pActiveView = (CPlcView*)CreatePlcView(pPlc);
+ }
+ ASSERT(m_pActiveView);
+ if (m_pActiveView->GetContext() != (void*)pPlc) {
+ m_pActiveView->SetWindowText(pPlc->getName().c_str());
+ m_pActiveView->SetContext(pPlc);
+ }
+ }
+ }
+
+ pAny->release();
+ }, [&]() -> void {
+ // onComplete
+ }, [&](IThrowable* pThrowable) -> void {
+ // onErrorm
+ pThrowable->printf();
+ });
+
+ theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
+ ->subscribe(m_pObserver);
+ }
+}
BOOL CBoounionPLCDlg::OnInitDialog()
{
@@ -129,12 +175,19 @@
m_pPagePlcList->ShowWindow(SW_SHOW);
+ // 主窗口页
+ m_pMainContainer = new CMainContainer();
+ m_pMainContainer->Create(IDD_MAIN_CONTAINER, this);
+ m_pMainContainer->ShowWindow(SW_SHOW);
+
+
// 菜单
CMenu menu;
menu.LoadMenu(IDR_MENU_APP);
SetMenu(&menu);
+ InitRxWindows();
ShowWindow(SW_MAXIMIZE);
Resize();
@@ -278,12 +331,28 @@
m_pPagePlcList = nullptr;
}
+ if (m_pMainContainer != nullptr) {
+ m_pMainContainer->DestroyWindow();
+ delete m_pMainContainer;
+ m_pMainContainer = nullptr;
+ }
+
+ if (m_pActiveView != nullptr) {
+ m_pActiveView->DestroyWindow();
+ delete m_pActiveView;
+ m_pActiveView = nullptr;
+ }
+
if (m_hbrBkgnd != nullptr) {
::DeleteObject(m_hbrBkgnd);
m_hbrBkgnd = nullptr;
}
-}
+ if (m_pObserver != nullptr) {
+ m_pObserver->unsubscribe();
+ m_pObserver = NULL;
+ }
+}
void CBoounionPLCDlg::OnSize(UINT nType, int cx, int cy)
{
@@ -300,13 +369,15 @@
CRect rcClient, rcItem;
GetClientRect(&rcClient);
+ int x = 0;
int y = 0;
m_pTopToolbar->MoveWindow(0, 0, rcClient.Width(), TOOLBAR_HEIGHT);
y += TOOLBAR_HEIGHT;
m_pPagePlcList->MoveWindow(0, y, PAGE_PLC_LIST_WIDTH, rcClient.Height() - y - 2);
+ x = PAGE_PLC_LIST_WIDTH;
+ m_pMainContainer->MoveWindow(x + 1, y, rcClient.Width() - x - 0, rcClient.bottom - y - 2);
}
-
HBRUSH CBoounionPLCDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
@@ -424,3 +495,62 @@
return 0;
}
+
+LRESULT CBoounionPLCDlg::OnViewActive(WPARAM wParam, LPARAM lParam)
+{
+ CBaseView* pView = (CBaseView*)wParam;
+ int code = (int)lParam;
+ if (code == MA_ACTIVATE || code == MA_ACTIVATEANDEAT) {
+
+ }
+
+
+ return 0;
+}
+
+LRESULT CBoounionPLCDlg::OnViewBtnClicked(WPARAM wParam, LPARAM lParam)
+{
+ int id = (int)lParam;
+ if (id == VIEW_TOOL_BTN_CLOSE) {
+ CloseView((CBaseView*)wParam);
+ }
+
+ return 0;
+}
+
+LRESULT CBoounionPLCDlg::OnViewBtnMenuItem(WPARAM wParam, LPARAM lParam)
+{
+ UINT id = (UINT)lParam;
+
+ return 0;
+}
+
+CBaseView* CBoounionPLCDlg::CreatePlcView(CPLC* pPlc)
+{
+ CPlcView* pDlg = new CPlcView(m_pMainContainer);
+ pDlg->SetContext(pPlc);
+ pDlg->Create(IDD_VIEW_PLC, m_pMainContainer);
+
+ CString strIcon0, strIcon1, strIcon2, strIcon3;
+ strIcon0.Format(_T("%s\\Res\\small_close0.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon1.Format(_T("%s\\Res\\small_close1.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon2.Format(_T("%s\\Res\\small_close2.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon3.Format(_T("%s\\Res\\small_close3.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ pDlg->AddToolBtn(VIEW_TOOL_BTN_CLOSE,
+ (LPTSTR)(LPCTSTR)strIcon0,
+ (LPTSTR)(LPCTSTR)strIcon1,
+ (LPTSTR)(LPCTSTR)strIcon2,
+ (LPTSTR)(LPCTSTR)strIcon3, "关闭");
+ pDlg->SetWindowText(pPlc->getName().c_str());
+ m_pMainContainer->Resize();
+
+ return pDlg;
+}
+
+void CBoounionPLCDlg::CloseView(CBaseView* pView)
+{
+ pView->DestroyWindow();
+ delete (CBaseView*)pView;
+ m_pActiveView = nullptr;
+ m_pMainContainer->Resize();
+}
--
Gitblit v1.9.3