CListCtrl 拖动滚动条闪烁,添加LVS_EX_DOUBLEBUFFER风格,重绘的网格线不显示。解决方法
CListCtrl 拖动滚动条闪烁,添加LVS_EX_DOUBLEBUFFER风格,重绘的网格线不显示。
如题, 添加LVS_EX_DOUBLEBUFFER风格后,拖动滚动条,重绘的网格线就不显示了,非要鼠标在列表上晃动一下才会显示出来,而且拖动一列的大小时,那一列的网格也不显示了,也需要再次晃动一下鼠标。请问这是为什么?
重绘的网格线的代码
ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST1, &CMy33Dlg::OnNMCustomdrawList1)
void CMy33Dlg::OnNMCustomdrawList1(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
*pResult = 0;
CListCtrl* pList = (CListCtrl*)GetDlgItem(IDC_LIST1);
if((pList->GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
{
CClientDC dc(this);
CPen newPen, *oldPen;
newPen.CreatePen(PS_SOLID, 1, RGB(0,0,0));
oldPen = dc.SelectObject(&newPen);
CHeaderCtrl* pHeader = pList->GetHeaderCtrl();
int nColumnCount = pHeader->GetItemCount();
RECT rect;
pHeader->GetClientRect(&rect);
int top = rect.bottom;
int left = rect.left;
pList->GetWindowRect(&rect);
int left1 = rect.left;
ScreenToClient(&rect);
CRect ss;
pList->GetClientRect(&ss);
CRect dlgRect;
GetWindowRect(&dlgRect);
CRect dlgRect1;
GetClientRect(&dlgRect1);
int borderx = 0 - pList->GetScrollPos(SB_HORZ);
for(int i = 0; i < nColumnCount;i++)
{
borderx += pList->GetColumnWidth(i);
if(borderx + (rect.left - dlgRect1.left)+2 >= ss.right + 12) break;
if (borderx + (rect.left - dlgRect1.left)+2 <= left1 - dlgRect.left + 2) continue;
dc.MoveTo(borderx + (rect.left - dlgRect1.left)+2, top + (rect.top - dlgRect1.top)+2);
dc.LineTo(borderx + (rect.left - dlgRect1.left)+2, ss.bottom+9);//rect.bottom - (dlgRect1.bottom - rect.bottom));
}
if(!pList->GetItemRect(0,&rect,LVIR_BOUNDS))
return;
int height = rect.bottom - rect.top;
pList->GetWindowRect(&rect);
//int width = rect.right - rect.left - 10;
for(int i = 1; i<= pList->GetCountPerPage(); i++)
{
dc.MoveTo(rect.left - dlgRect.left + 2, top + height*(i+1) -2);
dc.LineTo(ss.right + 12, top + height*(i+1) - 2);
}
dc.SelectObject(oldPen);
newPen.DeleteObject();
}
}
------解决方案--------------------
回去找找资料,明天再来回答。
如题, 添加LVS_EX_DOUBLEBUFFER风格后,拖动滚动条,重绘的网格线就不显示了,非要鼠标在列表上晃动一下才会显示出来,而且拖动一列的大小时,那一列的网格也不显示了,也需要再次晃动一下鼠标。请问这是为什么?
重绘的网格线的代码
ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST1, &CMy33Dlg::OnNMCustomdrawList1)
void CMy33Dlg::OnNMCustomdrawList1(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
*pResult = 0;
CListCtrl* pList = (CListCtrl*)GetDlgItem(IDC_LIST1);
if((pList->GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
{
CClientDC dc(this);
CPen newPen, *oldPen;
newPen.CreatePen(PS_SOLID, 1, RGB(0,0,0));
oldPen = dc.SelectObject(&newPen);
CHeaderCtrl* pHeader = pList->GetHeaderCtrl();
int nColumnCount = pHeader->GetItemCount();
RECT rect;
pHeader->GetClientRect(&rect);
int top = rect.bottom;
int left = rect.left;
pList->GetWindowRect(&rect);
int left1 = rect.left;
ScreenToClient(&rect);
CRect ss;
pList->GetClientRect(&ss);
CRect dlgRect;
GetWindowRect(&dlgRect);
CRect dlgRect1;
GetClientRect(&dlgRect1);
int borderx = 0 - pList->GetScrollPos(SB_HORZ);
for(int i = 0; i < nColumnCount;i++)
{
borderx += pList->GetColumnWidth(i);
if(borderx + (rect.left - dlgRect1.left)+2 >= ss.right + 12) break;
if (borderx + (rect.left - dlgRect1.left)+2 <= left1 - dlgRect.left + 2) continue;
dc.MoveTo(borderx + (rect.left - dlgRect1.left)+2, top + (rect.top - dlgRect1.top)+2);
dc.LineTo(borderx + (rect.left - dlgRect1.left)+2, ss.bottom+9);//rect.bottom - (dlgRect1.bottom - rect.bottom));
}
if(!pList->GetItemRect(0,&rect,LVIR_BOUNDS))
return;
int height = rect.bottom - rect.top;
pList->GetWindowRect(&rect);
//int width = rect.right - rect.left - 10;
for(int i = 1; i<= pList->GetCountPerPage(); i++)
{
dc.MoveTo(rect.left - dlgRect.left + 2, top + height*(i+1) -2);
dc.LineTo(ss.right + 12, top + height*(i+1) - 2);
}
dc.SelectObject(oldPen);
newPen.DeleteObject();
}
}
------解决方案--------------------
回去找找资料,明天再来回答。