// LogSearchBar.h - 日志列表搜索条(嵌入式,固定在右侧) #pragma once #include #include #include #define IDC_LOG_SEARCH_EDIT 5001 #define IDC_LOG_SEARCH_PREV 5002 #define IDC_LOG_SEARCH_NEXT 5003 #define IDC_LOG_SEARCH_COUNT 5004 #define IDC_LOG_SEARCH_CLEAR 5005 class CLogSearchBar : public CWnd { public: CLogSearchBar(); virtual ~CLogSearchBar(); // pParent: 主对话框; pList: 要搜索的 CListCtrl(m_CList_Message) BOOL Create(CWnd* pParent, CListCtrl* pList); void InvalidateSearch(); // 当前命中行的列表索引,无命中返回 -1(纯内存读) int GetHighlightedRow() const { if (m_nCurrentIndex < 0 || m_nCurrentIndex >= (int)m_Results.size()) return -1; return m_Results[m_nCurrentIndex]; } protected: CListCtrl* m_pList = nullptr; CEdit m_editSearch; CButton m_btnPrev; CButton m_btnNext; CButton m_btnClear; CStatic m_staticCount; std::vector m_Results; // 匹配行索引 int m_nCurrentIndex = -1; void DoSearch(); void GotoMatch(int idx); void UpdateCountText(); void LayoutControls(int cx, int cy); DECLARE_MESSAGE_MAP() afx_msg int OnCreate(LPCREATESTRUCT lpcs); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnEnChangeSearch(); afx_msg void OnBnClickedPrev(); afx_msg void OnBnClickedNext(); afx_msg void OnBnClickedClear(); static const UINT TIMER_SEARCH = 1; static const UINT SEARCH_DELAY_MS = 400; };