DOC: CListBox::ItemFromPoint() Works Only in Windows 95Last reviewed: July 10, 1997Article ID: Q148498 |
2.10 2.20 4.00 4.10
WINDOWS NT
kbprg kbdocerr kbcode kbdocfix
The information in this article applies to:
SUMMARYThe 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 INFORMATIONThe 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 CodeThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |