Fix: Match thumbnail column selection bg on listview focus loss

This commit is contained in:
yuanyuanxiang
2026-05-13 21:44:26 +02:00
parent e762e3cbd1
commit ead4f909ee

View File

@@ -8862,6 +8862,9 @@ void CMy2015RemoteDlg::OnNMCustomdrawOnline(NMHDR* pNMHDR, LRESULT* pResult)
}
if (clientID == 0) return;
bool isSelected = (m_CList_Online.GetItemState(nRow, LVIS_SELECTED) & LVIS_SELECTED) != 0;
// 失焦的选中态:系统把其它列从 HIGHLIGHT(蓝)切到 3DFACE(浅灰)。col 0 也要跟着切,
// 否则只有第一列保持蓝,与其它列脱节。检测 listview 是否持有键盘焦点即可。
bool hasFocus = (::GetFocus() == m_CList_Online.GetSafeHwnd());
// 用 GetItemRect + GetColumnWidth(0) 算 col 0 的矩形 —— 比 pLVCD->nmcd.rc 更
// 可靠:后者在 POSTPAINT 阶段对虚拟列表有时返回空 / 行片段。
@@ -8889,10 +8892,14 @@ void CMy2015RemoteDlg::OnNMCustomdrawOnline(NMHDR* pNMHDR, LRESULT* pResult)
}
HBITMAP hbmOld = (HBITMAP)::SelectObject(hMemDC, hbmCell);
// 全部画在 (0,0)-(cellW,cellH) 局部坐标
// 全部画在 (0,0)-(cellW,cellH) 局部坐标。底色与系统对其它列的渲染同步:
// 未选中 → COLOR_WINDOW (白)
// 选中 + 聚焦 → COLOR_HIGHLIGHT (蓝)
// 选中 + 失焦 → COLOR_3DFACE (浅灰,与失焦后其它列一致)
RECT rcLocal = { 0, 0, cellW, cellH };
HBRUSH hBg = ::GetSysColorBrush(isSelected ? COLOR_HIGHLIGHT : COLOR_WINDOW);
::FillRect(hMemDC, &rcLocal, hBg);
int bgIdx = !isSelected ? COLOR_WINDOW
: (hasFocus ? COLOR_HIGHLIGHT : COLOR_3DFACE);
::FillRect(hMemDC, &rcLocal, ::GetSysColorBrush(bgIdx));
auto it = m_HostThumbnails.find(clientID);
bool hasBmp = (it != m_HostThumbnails.end() && it->second.bmp);
@@ -8904,8 +8911,9 @@ void CMy2015RemoteDlg::OnNMCustomdrawOnline(NMHDR* pNMHDR, LRESULT* pResult)
HFONT hListFont = (HFONT)m_CList_Online.SendMessage(WM_GETFONT, 0, 0);
HFONT hOldFont = hListFont ? (HFONT)::SelectObject(hMemDC, hListFont) : nullptr;
::SetBkMode(hMemDC, TRANSPARENT);
// 文字色匹配底色:仅"选中+聚焦"用 HIGHLIGHTTEXT(白),其它(含失焦选中)用 WINDOWTEXT(黑)
::SetTextColor(hMemDC, ::GetSysColor(
isSelected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
(isSelected && hasFocus) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
const wchar_t* placeholder = supportsPreview ? L"" : L"N/A";
::DrawTextW(hMemDC, placeholder, -1, &rcLocal,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);