From 6747bc043d0af20d6fa02a6cf385d81eb44643d0 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期六, 28 六月 2025 11:29:42 +0800
Subject: [PATCH] 1.自绘按钮,修改为支持文字在按钮下,或在按钮右。 2.日志页,修改为“包含”和“排除”关键字,以及正则表达式的支持,便于在调试过程中快速观察日志
---
SourceCode/Bond/Servo/LogEdit.cpp | 64 ++++++++++++++++++++-----------
1 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/SourceCode/Bond/Servo/LogEdit.cpp b/SourceCode/Bond/Servo/LogEdit.cpp
index 3b4742f..1b08345 100644
--- a/SourceCode/Bond/Servo/LogEdit.cpp
+++ b/SourceCode/Bond/Servo/LogEdit.cpp
@@ -21,12 +21,13 @@
BEGIN_MESSAGE_MAP(CLogEdit, CEdit)
ON_WM_CONTEXTMENU()
ON_WM_VSCROLL()
+ ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
void CLogEdit::SetMaxLineCount(int line)
{
m_nMaxLines = line;
- m_nTrimLines = min(m_nMaxLines, 100);
+ m_nTrimLines = min(m_nMaxLines, 4000);
}
void CLogEdit::OnContextMenu(CWnd* pWnd, CPoint point)
@@ -60,6 +61,13 @@
CEdit::OnVScroll(nSBCode, nPos, pScrollBar);
}
+BOOL CLogEdit::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
+{
+ // 每次滚动时检查是否还在底部
+ m_bAutoScroll = IsScrollBarAtBottom();
+ return CEdit::OnMouseWheel(nFlags, zDelta, pt);
+}
+
BOOL CLogEdit::IsScrollBarAtBottom()
{
SCROLLINFO si = { sizeof(si), SIF_ALL };
@@ -69,31 +77,41 @@
void CLogEdit::AppendText(const char* pszText)
{
- SetRedraw(FALSE);
+ SetRedraw(FALSE);
- // 裁剪逻辑
- int totalLines = GetLineCount();
- if (totalLines > m_nMaxLines) {
- // 获取要删除的字符范围
- int startChar = LineIndex(0); // 第0行首字符位置
- int endChar = LineIndex(m_nTrimLines); // 第N行首字符位置
+ // 剪切过多行
+ int totalLines = GetLineCount();
+ if (totalLines > m_nMaxLines) {
+ int startChar = LineIndex(0);
+ int endChar = LineIndex(m_nTrimLines);
+ if (startChar >= 0 && endChar > startChar) {
+ SetSel(startChar, endChar);
+ ReplaceSel(_T(""));
+ }
+ }
- if (startChar >= 0 && endChar > startChar) {
- SetSel(startChar, endChar);
- ReplaceSel(_T("")); // 删除前面行
- }
- }
+ // 保存当前选择
+ int start, end;
+ GetSel(start, end);
+ bool hasSelection = (start != end);
+ int endPos = GetWindowTextLength();
+ SetSel(endPos, endPos);
+ ReplaceSel(lpszText);
- int len = GetWindowTextLength();
- SetSel(len, len);
- ReplaceSel(pszText);
+ if (m_bAutoScroll && !hasSelection) {
+ LineScroll(GetLineCount());
+ }
- if (m_bAutoScroll) {
- LineScroll(GetLineCount());
- }
+ // 恢复选择
+ if (hasSelection) {
+ SetSel(start, end);
+ }
- SetRedraw(TRUE);
- Invalidate();
- UpdateWindow();
-}
\ No newline at end of file
+ SetRedraw(TRUE);
+
+ if (m_bAutoScroll && !hasSelection) {
+ Invalidate();
+ UpdateWindow();
+ }
+}
--
Gitblit v1.9.3