CListBox类的ItemFromPoint函数用法
时间: 2024-01-04 19:04:19 浏览: 98
CListBox类的ItemFromPoint函数是用于获取指定点坐标下的列表框项的索引值。其函数原型如下:
int ItemFromPoint(CPoint point, BOOL& bOutside) const;
其中,point参数是指定点坐标,bOutside参数用于返回指定点是否在列表框的边界外面。函数返回值是指定点坐标下的列表框项的索引值,如果指定点并不在列表框项上,则返回LB_ERR。如果bOutside参数为TRUE,则表示指定点在列表框的边界外面。
使用该函数的步骤如下:
1. 创建一个CListBox类的对象。
2. 调用Create函数创建一个列表框控件。
3. 调用ItemFromPoint函数获取指定点坐标下的列表框项的索引值。
例如:
CListBox listBox;
listBox.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY, CRect(20, 20, 200, 200), pParentWnd, IDC_LISTBOX);
CPoint pt(50, 50);
BOOL bOutside;
int nIndex = listBox.ItemFromPoint(pt, bOutside);
if (nIndex != LB_ERR) {
// Do something with the selected item
}
else {
if (bOutside) {
// The point is outside the list box
}
else {
// The point is inside the list box, but not on an item
}
}
阅读全文
相关推荐

















