// CPjPage1.cpp: 实现文件 // #include "stdafx.h" #include "Servo.h" #include "CCjPage2.h" #include "afxdialogex.h" #include "RecipeManager.h" // CPjPage1 对话框 IMPLEMENT_DYNAMIC(CCjPage2, CCjPageBase) CCjPage2::CCjPage2(CWnd* pParent /*=nullptr*/) : CCjPageBase(IDD_CJ_PAGE2, pParent) { } CCjPage2::~CCjPage2() { } void CCjPage2::DoDataExchange(CDataExchange* pDX) { CCjPageBase::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CCjPage2, CCjPageBase) ON_WM_DESTROY() ON_EN_CHANGE(IDC_EDIT_PJ_ID, &CCjPage2::OnEnChangeEditPjId) ON_CBN_SELCHANGE(IDC_COMBO_RECIPE, &CCjPage2::OnCbnSelchangeComboRecipe) END_MESSAGE_MAP() // CPjPage1 消息处理程序 void CCjPage2::OnSetContext(void* pContext) { UpdatePjData(); } BOOL CCjPage2::OnInitDialog() { CCjPageBase::OnInitDialog(); // 若你的资源里有一个占位的 ListCtrl(比如 IDC_LIST1),这里做子类化: m_selector.SubclassDlgItem(IDC_LIST_SELECTOR, this); // 初始化:4 列 × 8 行 m_selector.InitGrid(4, 8); m_selector.SetColumnWidths(100, 180); m_selector.SetRowHeight(36); // 设置列信息 m_selector.SetPortInfo(0, _T("Port 1"), _T("Carrier A")); m_selector.SetPortInfo(1, _T("Port 2"), _T("Carrier B")); m_selector.SetPortInfo(2, _T("Port 3"), _T("Carrier C")); m_selector.SetPortInfo(3, _T("Port 4"), _T("Carrier D")); // 设置部分 Glass(核心ID固定) m_selector.SetSlotGlass(0, 0, TRUE, _T("001"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(0, 1, TRUE, _T("002"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(0, 3, TRUE, _T("004"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(1, 0, TRUE, _T("101"), CCarrierSlotSelector::MAT_G2); m_selector.SetSlotGlass(1, 1, TRUE, _T("102"), CCarrierSlotSelector::MAT_G2); m_selector.SetSlotGlass(1, 2, TRUE, _T("103"), CCarrierSlotSelector::MAT_G2); m_selector.SetSlotGlass(1, 5, TRUE, _T("106"), CCarrierSlotSelector::MAT_G2); m_selector.SetSlotGlass(1, 7, TRUE, _T("108"), CCarrierSlotSelector::MAT_G2); m_selector.SetSlotGlass(2, 5, TRUE, _T("206"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(2, 6, TRUE, _T("207"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(2, 7, TRUE, _T("208"), CCarrierSlotSelector::MAT_G1); m_selector.SetSlotGlass(3, 0, TRUE, _T("301"), CCarrierSlotSelector::MAT_G1); // 锁定 Port 1(示例) m_selector.SetPortAllocated(0, TRUE, _T("ProcessJob 1")); UpdatePjData(); ; return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CCjPage2::OnDestroy() { CCjPageBase::OnDestroy(); // TODO: 在此处添加消息处理程序代码 } void CCjPage2::Resize() { CCjPageBase::Resize(); /* CWnd* pItem; CRect rcClient, rcItem; GetClientRect(&rcClient); pItem = GetDlgItem(IDC_LABEL_TITLE); pItem->GetWindowRect(&rcItem); pItem->MoveWindow(12, 8, rcClient.Width() - 24, rcItem.Height()); */ } void CCjPage2::OnApply() { //SERVO::CProcessJob* if (m_pContext == nullptr) return; SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)m_pContext; // 更新名称 char szBuffer[256]; GetDlgItemText(IDC_EDIT_PJ_ID, szBuffer, 256); pProcessJob->setId(std::string(szBuffer)); // 更新配方 CString strRecipe; CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_RECIPE); int idx = pComboBox->GetCurSel(); if (idx >= 0) { pComboBox->GetLBText(idx, strRecipe); #ifdef UNICODE CT2A utf8Str(strRecipe, CP_UTF8); std::string recipe(utf8Str); #else std::string recipe(strRecipe.GetString()); #endif pProcessJob->setRecipe(SERVO::RecipeMethod::NoTuning, recipe); } ContentChanged(1); } void CCjPage2::UpdatePjData() { m_bContentChangedLock = TRUE; CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_RECIPE); pComboBox->ResetContent(); std::vector vecRecipe = RecipeManager::getInstance().getAllPPID(); for (const auto& recipe : vecRecipe) { pComboBox->AddString(CString(recipe.c_str())); } if (m_pContext) { SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)m_pContext; SetDlgItemText(IDC_EDIT_PJ_ID, pProcessJob->id().c_str()); int idx = pComboBox->FindStringExact(-1, pProcessJob->recipeSpec().c_str()); if (idx != CB_ERR) pComboBox->SetCurSel(idx); } m_bContentChangedLock = FALSE; } void CCjPage2::OnEnChangeEditPjId() { ContentChanged(0); } void CCjPage2::OnCbnSelchangeComboRecipe() { ContentChanged(0); }