Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtWFF and Right Mouse button menus Collapse All
Subject Author Date
Art Poley Sep 22, 2004 - 2:35 PM

I presently have a treectrl class that has the following callback setup:


ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)


void CProcessTree::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)


In my callback, I determine which tree item was selected and display a menu relative to that particular tree item.


What I’m noticing is the tree item expanding on the right mouse button, along with my menu being displayed.  It doesn’t expand all the time, but frequent enough to make it an issue to the user.


That being said, my question is how to have the tree item NOT expand on the right mouse button processing. 


Thanks in advance,


Art Poley


 

Technical Support Sep 23, 2004 - 7:05 AM

Dear Art,

We cannot reproduce the problem you described (expanding tree items with right mouse button clicking), but this is not a major problem. Your way of displaying menus means that the user is unable to display menu with the Context Menu key, which generates the WM_CONTEXTMENU message. The tree view common control does not generate WM_CONTEXTMENU menu message when its items are clicked with the right mouse button. Because of this, we recommend not using the NM_RCLICK notification message. The better way is to derive a class from CTreeCtrl and implement OnRButtonUp, OnRButtonDown and OnContextMenu message handlers in it, which may look like this:

    void CYourCustomTreeCtrl::OnRButtonUp(
        UINT nFlags,
        CPoint point
        ) 
    {
        nFlags;
        point;
    }
 
    void CYourCustomTreeCtrl::OnRButtonDown(
        UINT nFlags,
        CPoint point
    ) 
    {
        nFlags;
        TVHITTESTINFO _tv_ht_info;
        ::memset(
            &_tv_ht_info,
            0,
            sizeof(TVHITTESTINFO)
            );
        _tv_ht_info.pt = point;
        HitTest( &_tv_ht_info );
        if( _tv_ht_info.hItem != NULL )
        {
            HTREEITEM htiSel = GetSelectedItem();
            if( htiSel != _tv_ht_info.hItem )
                SelectItem( _tv_ht_info.hItem );
            if( ( _tv_ht_info.flags &
                    (TVHT_ONITEMLABEL
                        | TVHT_ONITEMICON)
                    ) != 0 )
            {
                SendMessage( WM_CONTEXTMENU );
            }
        } // if( _tv_ht_info.hItem != NULL )
    }
The CYourCustomTreeCtrl::OnContextMenu method should track the context menu. It is invoked when either the right mouse button, or the Context Menu key has been pressed. In the above code, the right button click changes the currently selected item. So, your OnContextMenu method should display a menu for the selected item. You may change this strategy by using the currently highlighted item instead of selected one (e.g, as it is implemented in MSDN .NET). In this case, highlight the item before sending the WM_CONTEXTMENU message and then restore it back.