Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - No right-click notify for CXTPTreeBase
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

No right-click notify for CXTPTreeBase

 Post Reply Post Reply
Author
Message
xsensordev View Drop Down
Groupie
Groupie


Joined: 19 August 2021
Location: Canada
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote xsensordev Quote  Post ReplyReply Direct Link To This Post Topic: No right-click notify for CXTPTreeBase
    Posted: 20 September 2021 at 2:19pm
Toolkit Pro 20.0.0

I'm not able to receive a right-click event (used for context menu purposes) with any CXTPTreeBase derived tree controls.  The CXTPTreeBase::OnRButtonDown handler in XTPTreeBase.cpp comments out the NM_RCLICK notification.  

I can put this back in for my copy of Toolkit Pro, but its not clear as to why it was removed in the first place.
Back to Top
xsensordev View Drop Down
Groupie
Groupie


Joined: 19 August 2021
Location: Canada
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote xsensordev Quote  Post ReplyReply Direct Link To This Post Posted: 20 September 2021 at 4:19pm
For the record, Codejock's commented out notify code in CXTPTreeBase doesn't work because the m_pTreeCtrl is owned by the CXTPTreeBase derived control and not the window on which the control is placed.

However this works:
void CXTPTreeBase::OnRButtonDown(UINT /*nFlags*/, CPoint point)
{
    if (m_pTreeCtrl->GetStyle() & TVS_SINGLEEXPAND)
    {
        m_pTreeCtrl->Default();
        return;
    }

    // hittest to get the tree item under the cursor
    // and select it.
    UINT uFlags = 0;
    HTREEITEM hItem = m_pTreeCtrl->HitTest(point, &uFlags);
    if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)
    {
        // if the item is not selected, clear previous
        // selections and select the item under cursor.
        if (!IsSelected(hItem))
        {
            SelectAll(FALSE);
            SelectItem(hItem);
        }
    }
    else
    {
        // clear previous selections.
        SelectAll(FALSE);
    }

    // call Default() so correct notification messages are
    // sent such as TVN_BEGINRDRAG.
    m_pTreeCtrl->Default();

    CWnd* pParent = m_pTreeCtrl->GetOwner();
    CWnd* pGrandParent = (pParent != NULL) ? pParent->GetOwner() : NULL;

    HWND hWnd = (pGrandParent != NULL) ? pGrandParent->m_hWnd : NULL;

    if (::IsWindow(hWnd))
    {
        // construct a NMHDR struct...
        NMHDR mHDR;
        mHDR.hwndFrom = pParent->m_hWnd;
        mHDR.code = NM_RCLICK;
        mHDR.idFrom = m_pTreeCtrl->GetDlgCtrlID();

        // and send a WM_NOTIFY message to our owner.
        SendNotify(&mHDR);
    }
}
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.109 seconds.