Right mouse button click in CTreeView? 
Author Message
 Right mouse button click in CTreeView?

I have splitter window and two CTreeView. In each of view I want to cath
right mouse button click. I tried to implement handler on WM_RBUTTONDOWN
but function is not called in my view although I see message using Spy. I
also tried to implement ON_NOTIFY for NM_RCLICK and it is sent normally but
I don't know how to retreive mouse pointer position from this handler.
Please help!



Mon, 31 May 1999 03:00:00 GMT  
 Right mouse button click in CTreeView?

You might try inserting the on context menu component and using it.
However, I also have an SDI CTreeView splitter windows and here is what i
did to get solve what sounds like a similar problem.  
        You may want to trap the PreTranslateMessage to check for the right click
message.    
If you aren't getting it in this override, check your message map macros.
Try this for right mouse clicks in the CTreeView to display a context menu
as a test:

HEADER:

protected:
        afx_msg void OnContextMenu(CWnd*, CPoint point);
        virtual BOOL PreTranslateMessage(MSG* pMsg);
        afx_msg void OnRclick(NMHDR* pNMHDR, LRESULT* pResult);

CODE:

BEGIN_MESSAGE_MAP(CDbTreeView, CTreeView)
        //{{AFX_MSG_MAP(CDbTreeView)
        ON_WM_CONTEXTMENU()
        ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CDbTreeView::PreTranslateMessage(MSG* pMsg)
{
        {
                // Shift+F10: show pop-up menu.
                if ((((pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) &&
// If we hit a key and
                        (pMsg->wParam == VK_F10) && (GetKeyState(VK_SHIFT) & ~1)) != 0) ||       //
it's Shift+F10 OR
                        (pMsg->message == WM_CONTEXTMENU))                                                                   // A Right Click
                {
                        CRect rect;
                        GetClientRect(rect);
                        ClientToScreen(rect);

                        CPoint point = rect.TopLeft();
                        point.Offset(5, 5);
                        OnContextMenu(NULL, point);

                        return TRUE;
                }
        }

        return CTreeView::PreTranslateMessage(pMsg);

Quote:
}

void CDbTreeView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
        NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

        HTREEITEM hRClickSel = NULL;
        UINT htFlags = TVHT_ONITEM;
        CPoint htPoint;

        // get mouse point
        GetCursorPos(&htPoint);
        ScreenToClient(&htPoint);

        // is there a tree item there?
        hRClickSel = GetTreeCtrl().HitTest(htPoint, &htFlags);

        if(hRClickSel != NULL)
        {       // yes a tree item is present

                // select it
                GetTreeCtrl().SelectItem( hRClickSel );

                // pop up a context menu
                ClientToScreen(&htPoint);
                htPoint.Offset(5, 5);
                OnContextMenu(NULL, htPoint);
        }

        *pResult = 0;

Quote:
}

void CDbTreeView::OnContextMenu(CWnd*, CPoint point)
{
        UINT htFlags = TVHT_ONITEM;
        HTREEITEM hRClickSel = GetTreeCtrl().GetSelectedItem();

        CMenu menu;
        VERIFY(menu.LoadMenu(CG_IDR_POPUP_DB_TREE_VIEW));
        CMenu* pPopup = menu.GetSubMenu(IMG_GROUPS);
        ASSERT(pPopup != NULL);

        CWnd* pWndPopupOwner = this;
        while (pWndPopupOwner->GetStyle() & WS_CHILD)
                pWndPopupOwner = pWndPopupOwner->GetParent();

        pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
                pWndPopupOwner);

Quote:
}



Quote:

> > I have splitter window and two CTreeView. In each of view I want to
> > cath right mouse button click. I tried to implement handler on
> > WM_RBUTTONDOWN but function is not called in my view although I see
> > message using Spy.



Tue, 01 Jun 1999 03:00:00 GMT  
 Right mouse button click in CTreeView?

You can override the default window procedure to get right mouse clicks. If
you add the procedure from Class Wizard, test message for
WM_RBUTTON[DOWN/UP/ETC]. The mouse point is contained in lParam
(x=LOWORD(lParam); y=HIWORD(lParam);), which is in client coords, so you
can use it directly for HitTest, etc.

Jeff Bell



Thu, 03 Jun 1999 03:00:00 GMT  
 Right mouse button click in CTreeView?

You don't always need to handle the up button messages.

Try the following:

void CMyView::OnRButtonDown( UINT nHitTest, CPoint point )
{
                // Do your button down coding here

                CTreeView::OnRButtonDown(nHitTest, point);

                // Do your button up coding here

Quote:
}

Hope this helps,
Dennis


Sat, 05 Jun 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Right mouse button click in CTreeView?

2. Right mouse button click in CTreeView?

3. Q: CTreeView->Shortcut Menu->Right mouse double click

4. Right mouse button w/CTreeView

5. x and y coordinates when i click right mouse button

6. Right button mouse click in CListBox

7. Overwriting Right Mouse Button click of edit boxes

8. Popup menu clicking the right mouse button

9. howto track a right mouse click from a dialogbar button

10. Dispatching right mouse click for a toolbar button

11. Help: Detect when right button is clicked above a button

12. CTreeView and Right Click

 

 
Powered by phpBB® Forum Software