LAPTOP-SNT8I5JK\Boounion
2025-01-13 288b0dcc26e075a957eda08315f2beb52c91d207
1.最左侧延时加载PLC列表,初始选中第一项;
已修改2个文件
28 ■■■■■ 文件已修改
SourceCode/Bond/BoounionPLC/PagePlcList.cpp 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/PagePlcList.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/PagePlcList.cpp
@@ -8,6 +8,8 @@
#include "Common.h"
#define ID_TIMER_INIT            1
// CPagePlcList 对话框
IMPLEMENT_DYNAMIC(CPagePlcList, CDialogEx)
@@ -36,6 +38,7 @@
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_MESSAGE(ID_MSG_TREE_CLICK_ITEM, OnTreeClickItem)
    ON_WM_TIMER()
END_MESSAGE_MAP()
@@ -113,7 +116,8 @@
    m_treeCtrl.SetBkColor(PAGE_PLC_LIST_BACKGROUND);
    m_treeCtrl.SetItemHeight(50);
    ReadPLCList();
    SetTimer(ID_TIMER_INIT, 200, nullptr);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
@@ -182,14 +186,24 @@
void CPagePlcList::ReadPLCList()
{
    HTREEITEM hItemFirst = nullptr;
    std::map<std::string, CPLC*>& plcs = theApp.m_model.getPlcMap();
    for (auto item : plcs) {
        HTREEITEM hItem = m_treeCtrl.InsertItem(item.second->getName().c_str(), nullptr, nullptr);
        m_treeCtrl.SetItemData(hItem, (DWORD_PTR)item.second);
        if (hItemFirst == nullptr) {
            hItemFirst = hItem;
        }
    }
    if (!plcs.empty()) {
        m_treeCtrl.ShowWindow(SW_SHOW);
        GetDlgItem(IDC_LABEL_NO_PLC)->ShowWindow(SW_HIDE);
    }
    if (hItemFirst != nullptr) {
        m_treeCtrl.SelectItem(hItemFirst);
        CPLC* pPlc = (CPLC*)m_treeCtrl.GetItemData(hItemFirst);
        theApp.m_model.notifyPtr(RX_CODE_SELECT_PLC, pPlc);
    }
}
@@ -215,3 +229,14 @@
    return nullptr;
}
void CPagePlcList::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (ID_TIMER_INIT == nIDEvent) {
        KillTimer(ID_TIMER_INIT);
        ReadPLCList();
    }
    CDialogEx::OnTimer(nIDEvent);
}
SourceCode/Bond/BoounionPLC/PagePlcList.h
@@ -43,4 +43,5 @@
    afx_msg void OnSize(UINT nType, int cx, int cy);
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    afx_msg LRESULT OnTreeClickItem(WPARAM wParam, LPARAM lParam);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
};