DOC: CListBox::ItemFromPoint() Works Only in Windows 95

Last reviewed: July 10, 1997
Article ID: Q148498
2.10 2.20 4.00 4.10 WINDOWS NT kbprg kbdocerr kbcode kbdocfix

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, versions 2.1, 2.2, 4.0, 4.1

SUMMARY

The CListBox member function ItemFromPoint() is not implemented in Win32s or Windows NT, but the documentation for the member function does not state this fact.

MORE INFORMATION

The ItemFromPoint() member function relies on the LB_ITEMFROMPOINT message which the documentation correctly states is supported only in Windows 95.

The Win32 SDK function LBItemFromPt() could be used as an alternative to CListBox::ItemFromPoint(). The drawback is LBItemFromPt() does not have exactly the same functionality. However, the workaround demonstrated in the folloiwng sample code does provide the same functionality.

Sample Code

The following code shows how ItemFromPoint() can be implemented to behave the same way on Windows 95, Win32s, and Windows NT. In this sample code, CMyListBox is derived from CListBox:

UINT CMyListBox::ItemFromPoint(CPoint pt,BOOL &bOutside) {

  // If we are on Win95, just call the base class
  if((BYTE)::GetVersion() >= 4)
    return CListBox::ItemFromPoint(pt,bOutside);

  if(GetCount()<1)
  {
    bOutside=TRUE;
    return 0;
  }

  CRect rectClient;
  GetClientRect(&rectClient);

  bOutside=!rectClient.PtInRect(pt);

  if (pt.y < rectClient.top)
    pt.y = rectClient.top;
  if (pt.x < rectClient.left)
    pt.x = rectClient.left;

  CRect rectCheck;
  int lastY = -1;

  for ( int nIndex = GetTopIndex(); nIndex < GetCount(); nIndex++)
  {
    GetItemRect(nIndex , &rectCheck);
    rectCheck.right+=1;
    if(!rectClient.PtInRect(rectCheck.TopLeft()))
      break;

    if (rectCheck.PtInRect(pt))
      return nIndex;

    // check for case where mouse is below the last item in a column of
    // an LBS_MULTICOLUMN list box
    if ( GetStyle() & LBS_MULTICOLUMN &&
         nIndex < GetCount()-1 &&
         pt.x>=rectCheck.left &&
         pt.x<rectCheck.right)
    {
        CRect rectNext;
        GetItemRect(nIndex+1, &rectNext);
        if (rectNext.left > rectCheck.left)
            return nIndex;
    }

    if (pt.y>=rectCheck.top)
        lastY = nIndex;
  }

  return lastY;
}

This documentation error was corrected in Visual C++ 32-bit Edition version 4.2.


KBCategory: kbprg kbdocerr kbcode kbdocfix
KBSubcategory: MfcUI
Additional reference words: 2.10 2.20 4.00 4.10 4.20 3.10 3.20 vcbuglist400
vcfixlist420
Keywords : MfcUI kbcode kbdocerr kbdocfix kbprg
Technology : kbMfc
Version : 2.10 2.20 4.00 4.10
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.