向編輯框追加文本後,自動滾動到最後一行保持可見。
// 追加文本
m_edit.SetSel(-1, -1); // 移動插入點到末尾
m_edit.ReplaceSel(newText + _T("\r\n"));
// 自動滾動到最後一行
m_edit.LineScroll(m_edit.GetLineCount());
SetSel(-1, -1):將光標移至文本末尾ReplaceSel:在光標處插入文本GetLineCount():獲取總行數LineScroll(n):垂直滾動 n 行(正數向下)void AppendText(CEdit& edit, LPCTSTR text) {
int len = edit.GetWindowTextLength();
edit.SetSel(len, len);
edit.ReplaceSel(text);
edit.ReplaceSel(_T("\r\n"));
edit.LineScroll(edit.GetLineCount()); // 強制滾動到底
}
ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL 樣式SetRedraw(FALSE) 結束後 TRUE 防止閃爍