Calculates the item index number given a point in combo box control client area coordinates.
C
LONG WINAPI SftBox_CalcIndexFromPoint(HWND hwndCtl, LPPOINT lpPt, BOOL* lpfMain);
C++
LONG CSftBox::CalcIndexFromPoint(LPPOINT lpPt, BOOL* lpfMain) const;
hwndCtl
The window handle of the combo box control.
lpPt
The x and y coordinates in pixels (relative to the upper left corner of the combo box control's client area), for which the item index number needs to be calculated. A location in the dropdown portion is also described relative to the combo box control's client area.
lpfMain
A pointer to a variable which receives a value indicating the portion of the combo box control where the point is located. TRUE is returned if the point is located in the static portion (or the edit control portion), FALSE is returned if the point is located in the dropdown portion or outside of both. This parameter cannot be NULL.
The return value is the zero-based index of the item at the given location. The return value is -1 if no item is located at the specified point.
The CalcIndexFromPoint function calculates the item index number given a point in combo box control client area coordinates.
The dropdown portion is tested first. If the location lpPt is on an item in the dropdown portion, the index of the item is returned.
If lpPt is at the bottom of the dropdown portion above a partially visible item, the dropdown portion does not provide an item index. If lpPt is in the empty area following the last item, the dropdown portion does not provide an item index either.
If the location lpPt is in the item area of the static portion (or of the edit control portion of a simple or dropdown combo box), the index of the currently selected item is returned (see GetCurSel), as this portion shows the selected item. If no item is selected, -1 is returned.
If the location lpPt is in the column or row/column header area of the dropdown portion or above or below both portions, -1 is returned. Only the vertical position of lpPt is used to locate an item in the dropdown portion, the horizontal position is not tested.
Use CalcCellFromPoint to determine the item index and the column number.
HWND hwndTarget = GetTarget(hwndSource);
if (IsOver(hwndTarget, lpInfo->hwnd)) {
// Over the other combo box, show where the item will be inserted
POINT pt = lpInfo->ptDrag;
BOOL fMain;
LONG index;
ScreenToClient(hwndTarget, &pt);
index = SftBox_CalcIndexFromPoint(hwndTarget, &pt, &fMain);
SftBox_SetDropHighlight(hwndTarget, fMain ? -1 : index, TRUE);
lpInfo->hCursor = LoadCursor(g_hInst, MAKEINTRESOURCE(IDC_DRAG));
} else {
SftBox_SetDropHighlight(hwndTarget, -1, FALSE);
lpInfo->hCursor = LoadCursor(NULL, IDC_NO);
}
}
{
LPSFTBOX_DRAGINFO lpInfo = source.GetDragInfo();
if (IsOver(target, lpInfo->hwnd)) {
// Over the other combo box, show where the item will be inserted
CPoint pt = lpInfo->ptDrag;
BOOL fMain;
target.ScreenToClient(&pt);
LONG index = target.CalcIndexFromPoint(&pt, &fMain);
target.SetDropHighlight(fMain ? -1 : index, TRUE);
lpInfo->hCursor = AfxGetApp()->LoadCursor(IDC_DRAG);
} else {
target.SetDropHighlight(-1, FALSE);
lpInfo->hCursor = AfxGetApp()->LoadStandardCursor(IDC_NO);
}
}See Also C/C++ API | Categories | Notifications