Article ID: 142960
Article Last Modified on 11/21/2006
CMyCheckListBox::CMyCheckListBox()
{
// the following code initializes the member variable
// m_nCheckWidth to be the width of a check box.
CBitmap bitmap;
BOOL bWin4 = (BYTE)GetVersion() >= 4;
HINSTANCE hInst = bWin4 ? NULL : LoadLibraryA("CTL3D32.DLL");
FARPROC pfnProc = (NULL == hInst) ? NULL : GetProcAddress(hInst,
(LPCSTR)21);
if (bWin4 || pfnProc != NULL)
VERIFY(bitmap.LoadBitmap(AFX_IDB_CHECKLISTBOX_95));
else
VERIFY(bitmap.LoadBitmap(AFX_IDB_CHECKLISTBOX_NT));
BITMAP bm;
bitmap.GetObject(sizeof (BITMAP), &bm);
m_nCheckWidth = bm.bmWidth / 3;
if (hInst)
FreeLibrary(hInst);
}
void CMyCheckListBox::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect itemRect;
CRect clientRect;
GetClientRect(clientRect);
for(int nIndex = GetTopIndex(); nIndex < GetCount(); nIndex++)
{
GetItemRect(nIndex, &itemRect);
if (!clientRect.PtInRect(itemRect.TopLeft()))
break;
if (itemRect.PtInRect(point) && IsEnabled(nIndex))
{
if (m_nStyle != BS_CHECKBOX && m_nStyle != BS_3STATE)
{
if (point.x - itemRect.left < m_nCheckWidth + 2)
{
CWnd* pParent = GetParent();
ASSERT_VALID(pParent);
int nModulo = (m_nStyle == BS_AUTO3STATE) ? 3 : 2;
int nCheck = GetCheck(nIndex);
nCheck = (nCheck == nModulo) ? nCheck - 1 : nCheck;
SetCheck(nIndex, (nCheck + 1) % nModulo);
InvalidateCheck(nIndex);
CListBox::OnLButtonDown(nFlags, point);
// Inform of check
pParent->SendMessage(WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE),
(LPARAM)m_hWnd);
return;
}
}
else
return; // Swallow LButtons for disabled items
}
}
// call CListBox::OnLButtonDown
// DO NOT call CCheckListBox::OnLButtonDown
CListBox::OnLButtonDown(nFlags, point);
}
void CMyCheckListBox::OnLButtonDblClk(UINT nFlags, CPoint point)
{
OnLButtonDown(nFlags, point);
}
Additional query words: kbVC400bug 4.00 4.10 vcfixlist420
Keywords: kbbug kbcode kbfix kblistbox kbnoupdate kbuidesign kbvc420fix KB142960