listcontrol: EnsureVisible() flickering
Hi,
I`ve installed a listcontrol item (report style) on a popup dialog.
I`ve created my own headercontrol and I use no scrollbars.
//called from the OnInitDialog() method of the dialog where the
listcontrol will be shown
void ImageListCtrl::Init(void)
{
//another way to hide scrollbars
InitializeFlatSB(this->m_hWnd);
FlatSB_EnableScrollBar(this->m_hWnd, SB_BOTH, ESB_DISABLE_BOTH);
}
Instead of using the scrollbars I want to use two buttons to scroll.
The size of the list can contain always 10 items.
Now if I click on the button to visit the next 10 items of the list, I
will always get some flickers. I`ve tried to use both methods Scroll()
and EnsureVisible() with no success.
The member of my listcontrol class is: ImageListCtrl m_ListNodes
//OnButtonClick() handler:
void CStatePage::OnBnClickedNlistNext()
{
UINT nbrOfItems = m_ListNodes.GetItemCount();
//get height of one item to now the scroll-size
CRect itemrect;
m_ListNodes.GetItemRect(0,&itemrect, LVIR_BOUNDS);
UINT height = itemrect.Height();
int top = m_ListNodes.GetTopIndex();
int newFirstItem=0;
if(top < (nbrOfItems -10))
newFirstItem = top+10;
else
newFirstItem = nbrOfItems - nbrOfItems %10;
m_ListNodes.EnsureVisible(newFirstItem , FALSE);
}
In my listcontrol class, I only use the OnPaint() handler:
void ImageListCtrl::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CMemDC memDC(&dc, rect);
//funky code to allow use to double buffer
//the onpaint calls for flicker free drawing
//of the list items
CRect headerRect;
GetDlgItem(0)->GetWindowRect(&headerRect);
ScreenToClient(&headerRect);
dc.ExcludeClipRect(&headerRect);
CRect clip;
memDC.GetClipBox(&clip);
memDC.FillSolidRect(clip, RGB(0,0,25));
SetTextBkColor(RGB(0,0,25));
SetTextColor(RGB(255,255,255));
DefWindowProc(WM_PAINT, (WPARAM)memDC->m_hDC, (LPARAM)0);
}
best regards
Hans