Fix: Stop the online-host list header from flickering
The list header is a child window of the list view, and LVS_EX_DOUBLEBUFFER only covers the item area. The list view was created without WS_CLIPCHILDREN, so every whole-list Invalidate or RedrawWindow also erased the header with the class background brush before repainting it. On top of that, AdjustColumnWidths ran on every WM_SIZE and issued an unconditional SetColumnWidth per column, and each call repaints the header. The result was an occasional one-frame blink of the header row: irregular, low frequency, and confined to the header because the item area is double-buffered. Both lists now carry WS_CLIPCHILDREN, RDW_ALLCHILDREN was dropped from the redraw calls that only need the list body (that flag forces child repaints even when they are clipped), and column widths are only set when they actually change. The header still needs its background erase, but only for the strip to the right of the last column: AdjustColumnWidths reserves 20px there and the header's own paint stops at the last column, so that strip is colored by WM_ERASEBKGND alone. Skipping the erase entirely left it black after a minimize/restore cycle, when the window contents are discarded. The header subclass now fills just that strip with COLOR_3DFACE and leaves the column area untouched, which keeps the flicker fix, and the needRefresh branch of OnSize forces an erase-redraw of the header so the strip is repainted on minimize/restore and maximize/normalize. Verified with a standalone probe that mirrors the list setup for the header erase counts, and by rebuilding the app and checking the minimize/restore case reported against the first version of this change. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
434812f87d
commit
7160ea8f42
3 files changed
+62
-12
No files matched your search
@@ -1623,6 +1623,10 @@ VOID CMy2015RemoteDlg::InitControl()
|
||||
m_CList_Online.SetExtendedStyle(style);
|
||||
m_CList_Online.SetParent(&m_GroupTab);
|
||||
m_CList_Online.ModifyStyle(WS_HSCROLL, 0);
|
||||
// 表头是列表的子窗口;LVS_EX_DOUBLEBUFFER 只给列表项做了双缓冲,表头没有。
|
||||
// 列表没有 WS_CLIPCHILDREN 时,任何整表 Invalidate/RedrawWindow 都会让表头
|
||||
// 先用类背景刷擦一帧再重画,表现为表头那行偶发闪一下。裁掉表头区域即可。
|
||||
m_CList_Online.ModifyStyle(0, WS_CLIPCHILDREN);
|
||||
// Tab 控件是列表的父窗口,添加 WS_CLIPCHILDREN 防止重绘时覆盖列表
|
||||
m_GroupTab.ModifyStyle(0, WS_CLIPCHILDREN);
|
||||
|
||||
@@ -1634,6 +1638,7 @@ VOID CMy2015RemoteDlg::InitControl()
|
||||
m_CList_Message.ModifyStyle(0, LVS_SHOWSELALWAYS);
|
||||
m_CList_Message.SetExtendedStyle(style);
|
||||
m_CList_Message.ModifyStyle(WS_HSCROLL, 0);
|
||||
m_CList_Message.ModifyStyle(0, WS_CLIPCHILDREN); // 同上:整表重绘不擦表头
|
||||
|
||||
m_nSplitPos = THIS_CFG.GetInt("settings", "SplitPos", 160);
|
||||
m_nSplitPos = max(60, min(m_nSplitPos, 600));
|
||||
@@ -3672,8 +3677,15 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy)
|
||||
m_CList_Online.AdjustColumnWidths();
|
||||
if (needRefresh) {
|
||||
CListCtrlEx::ScopedEraseBkgnd scope(m_CList_Online);
|
||||
m_GroupTab.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
|
||||
m_CList_Online.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
|
||||
// 不带 RDW_ALLCHILDREN:表头已是裁剪掉的子窗口,没必要跟着擦一帧
|
||||
m_GroupTab.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
|
||||
m_CList_Online.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
// 最小化还原/最大化和正常切换时窗口内容会丢,表头右端那条空带只能靠
|
||||
// 背景擦除上色(见 CHeaderCtrlEx::OnEraseBkgnd),这里显式让表头重画一次。
|
||||
// 擦除现在只补空带,不会重新引入表头闪烁。
|
||||
if (CHeaderCtrl* pHeader = m_CList_Online.GetHeaderCtrl()) {
|
||||
pHeader->RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
@@ -3715,7 +3727,7 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy)
|
||||
rc.bottom = cy-20;
|
||||
m_CList_Message.MoveWindow(rc);
|
||||
if (needRefresh) {
|
||||
m_CList_Message.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
|
||||
m_CList_Message.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
}
|
||||
auto total = cx - 24;
|
||||
for(int i=0; i<g_Column_Count_Message; ++i) { //遍历每一个列
|
||||
@@ -3723,7 +3735,10 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy)
|
||||
Temp/=g_Column_Message_Width; //看一看当前宽度占总长度的几分之几
|
||||
Temp*=total; //用原来的长度乘以所占的几分之几得到当前的宽度
|
||||
int lenth=Temp; //转换为int 类型
|
||||
m_CList_Message.SetColumnWidth(i,(lenth)); //设置当前的宽度
|
||||
// 只改真正变化的列:SetColumnWidth 会让表头重画一次(WM_SIZE 很频繁)
|
||||
if (m_CList_Message.GetColumnWidth(i) != lenth) {
|
||||
m_CList_Message.SetColumnWidth(i,(lenth)); //设置当前的宽度
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3760,13 +3775,13 @@ void CMy2015RemoteDlg::OnExitSizeMove()
|
||||
{
|
||||
__super::OnExitSizeMove();
|
||||
|
||||
// 拖拽调整大小结束后刷新列表,避免残影
|
||||
// 拖拽调整大小结束后刷新列表,避免残影(表头被 WS_CLIPCHILDREN 裁掉,不会闪)
|
||||
if (m_CList_Online.m_hWnd != NULL) {
|
||||
CListCtrlEx::ScopedEraseBkgnd scope(m_CList_Online);
|
||||
m_CList_Online.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
|
||||
m_CList_Online.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
}
|
||||
if (m_CList_Message.m_hWnd != NULL) {
|
||||
m_CList_Message.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
|
||||
m_CList_Message.RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
}
|
||||
// 更新搜索栏位置(跟随主窗口移动/调整大小)
|
||||
if (m_pSearchBar && m_pSearchBar->GetSafeHwnd() && m_pSearchBar->IsWindowVisible()) {
|
||||
|
||||
Reference in new issue
Block a user