NM_RCLICK handling

Hello Michał,

Thanks for your work,
CColumnTreeCtrl is a really good and neat control.
I need to show a context menu for a tree item,
and I encountered a problem when selecting an item with right click.

I'm using NM_RCLICK notification handling in parent dialog/view:

void CDemoView::OnTreeRclk(NMHDR* pNMHDR, LRESULT* pResult)
{

*pResult = 0;

CTreeCtrl& tree = GetTreeCtrl();

CPoint point, _point;
GetCursorPos(&point);

_point = point;
ScreenToClient(&_point);

UINT uFlags;
HTREEITEM hItem = tree.HitTest(_point,&uFlags);

if ((hItem != NULL) && (uFlags & (TVHT_ONITEM) ))
{
  tree.SelectItem(hItem);
  // show popup menu here
}

}

In this example hItem is always the item NEXT to one on which mouse pointer is.
In native CTreeCtrl everyting is ok.

Do you have an idea how to fix it?
Thanks in advance.

Re: NM_RCLICK handling

Try calling

tree.ScreenToClient(&_point);

Note that the tree is located below the header control, so it's client area is not exactly the same as the view's client area. Hope this helps.

Regards,
Michał

Re: NM_RCLICK handling

Thanks, it worked :)

I've also made the following modification in CColumnTreeCtrl source code to allow right click selection of an item:

void CColumnTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
    UINT uFlags;
    HTREEITEM m_selectedItem = HitTest(point, &uFlags);
    if (m_selectedItem != NULL)
        SelectItem(m_selectedItem);

    HandleMouse(WM_RBUTTONDOWN, nFlags, point);
}