Re: listcontrol: EnsureVisible() flickering
On 24 Nov., 22:23, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below...
On Wed, 24 Nov 2010 02:28:54 -0800 (PST), mfc <mfcp...@googlemail.com> wr=
ote:
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);
****
And why do you need this->m_hWnd? And for that matter, why this->? You=
could have written
InitializeFlagSB(*this);
and gotten the effect you desire. This is MFC. Of course, it is dee=
ply offensive that
there is not a CWnd::InitializeFlatSB method, but hey, it's only been aro=
und for a decade
or so, and we have to give the MFC folks a little time to catch up with r=
eality...
And oh, yes, did you notice it is no longer supported? RTFM.
****>}
Thank you for the hint. Is this the right place as well as the right
code to hide both scrollbars?
void ImageListCtrl::OnNcCalcSize(BOOL bCalcValidRects,
NCCALCSIZE_PARAMS* lpncsp)
{
//This removes both vertical and horizontal scrollbar. To remove
only vertical pass WS_VSCROLL
ModifyStyle( WS_HSCROLL | WS_VSCROLL, 0 );
CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}
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 scro=
ll-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(newFirstIt=
em , FALSE);
****
Which is probably going to cause another redraw, and recursive call on On=
Paint, and then
fall through and repaint everything again. You should consider a virtu=
al list control
(see Tom Serface's articles about virtual controls in the archives of thi=
s NG)
****
You`re right, with the virtual list it seems to work without
flickering....
One last question to this topic: if the whole list contains 14 items
and the list can show 10 items at the same time; how is it possible
that only the last four items are shown on the second page of the
list??? With "second page" I mean, that these items will be shown if
you click on the "next" button to show these items
#define NBR_OF_VISIBLE_ITEMS 10
void CStatePage::OnBnClickedNlistNext()
{
UINT nbrOfItems = m_ListNodes.GetItemCount();
int itemAtTop = m_ListNodes.GetTopIndex();
//insgesamt sollen 10 itesm angezeigt werden k=F6nnen pro Seite
int newTopItem = itemAtTop + 2 * NBR_OF_VISIBLE_ITEMS ;
if(newTopItem < nbrOfItems)
m_ListNodes.EnsureVisible(newTopItem - 1, FALSE);
else
m_ListNodes.EnsureVisible(nbrOfItems -1, FALSE);
}
With this code the second page will show the items [item5 - items14] -
but is it possible that this page will only show the list-items
[item11 - item14]?
best regards
Hans