Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

CalcIndexFromPoint

Calculates the item index number given a point in tree control client area coordinates.

C

int WINAPI SftTree_CalcIndexFromPoint(HWND hwndCtl, LPPOINT lpPt);
int WINAPI SftTree_CalcIndexFromPointEx(HWND hwndCtl, LPPOINT lpPt);
int WINAPI SftTreeSplit_CalcIndexFromPoint(HWND hwndCtl, LPPOINT lpPt);
int WINAPI SftTreeSplit_CalcIndexFromPointEx(HWND hwndCtl, LPPOINT lpPt);

C++

int CSftTree::CalcIndexFromPoint(LPPOINT lpPt) const;
int CSftTree::CalcIndexFromPointEx(LPPOINT lpPt) const;
int CSftTreeSplit::CalcIndexFromPoint(LPPOINT lpPt) const;
int CSftTreeSplit::CalcIndexFromPointEx(LPPOINT lpPt) const;

Parameters

hwndCtl

The window handle of the tree control.

lpPt

The x and y coordinates in pixels (relative to the upper left corner of the tree control), for which the item index number needs to be calculated.

Returns

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.

Comments

The CalcIndexFromPoint and CalcIndexFromPointEx functions calculate the item index number given a point in tree control client area coordinates.

If lpPt is at the bottom of the tree control above a partially visible item, CalcIndexFromPoint will return -1, CalcIndexFromPointEx returns the index of the item in this case.

CalcIndexFromPoint will return the index of the last item in the tree control if the lpPt location is above the empty area at the end of the item list. CalcIndexFromPointEx returns the index of the last item + 1 in this case.

If the location lpPt is in the column or row/column header area or outside the tree control client area, -1 is returned.

Examples

C

            // set the drop OK cursor
            lpInfo->fDropOK = TRUE;
            lpInfo->hCursor = LoadCursor(g_hInst, MAKEINTRESOURCE(IDC_DRAG));

            // update the drop target in the right tree
            pt = lpInfo->ptDrag;
            MapWindowPoints(HWND_DESKTOP, m_hwndRightTree, &pt, 1);
            index = SftTree_CalcIndexFromPointEx(m_hwndRightTree, &pt);
            SftTree_SetDropHighlight(m_hwndRightTree, index, TRUE);
            SftTree_StartAutoExpandTimer(m_hwndRightTree, index, FALSE, 0);

            // remember who is the drop target
            m_hwndLastTarget = m_hwndRightTree;
        }

    } else { // left side tree is the drop target

C++

            // set the drop OK cursor
            lpInfo->fDropOK = TRUE;
            lpInfo->hCursor = AfxGetApp()->LoadCursor(IDC_DRAG);

            // update the drop target in the right tree
            CPoint pt = lpInfo->ptDrag;
            ::MapWindowPoints(HWND_DESKTOP, m_RightTree.m_hWnd, &pt, 1);
            int index = m_RightTree.CalcIndexFromPointEx(&pt);
            m_RightTree.SetDropHighlight(index, TRUE);
            m_RightTree.StartAutoExpandTimer(index, FALSE, 0);

            // remember who is the drop target
            m_lastDropTarget = &m_RightTree;
        }

    } else { // left side tree is the drop target

See Also C/C++ API | Categories | Notifications