Question about overridden CListBox
Hi,
This is really a general query, as I got the list box to do what I
want. I'm just wondering can somebody who knows the innards of MFC
fill in some background.
I wanted to make a CListBox that cancels the (single) selection when
you click it again. It seems you have to derive a new class, but it
seems to work nicely when I do this and over-ride OnLButtonUp() as
follows:
void ClickyListBox::OnLButtonUp( UINT nFlags, CPoint point )
{
static int lastItem = -1;
BOOL bOutside;
int nItem = ItemFromPoint( point, bOutside );
if ( ! bOutside )
{
if ( nItem == lastItem )
{
SetCurSel( -1 );
lastItem = -1;
}
else
{
lastItem = nItem;
}
}
CListBox::OnLButtonUp(nFlags, point);
}
My questions:
I originally thought I should remove the call to the base-class
function, but in fact the ClickListBox acts oddly when I do this. What
is CListBox::OnLButtonUp doing that needs to be done?
Also, will the above work on all versions of Win32, or are there any
subtle message-ordering issues that will cause problems?
TIA for any comments. [Obviously I know that I should change lastItem
to a member variable in case there is going to be more than one
instance of the class.]
- Gerry Quinn