Print Page | Close Window

No right-click notify for CXTPTreeBase

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=24213
Printed Date: 25 April 2024 at 11:54am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: No right-click notify for CXTPTreeBase
Posted By: xsensordev
Subject: No right-click notify for CXTPTreeBase
Date 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.



Replies:
Posted By: xsensordev
Date 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);
    }
}



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net