Treeview: Right Mouse Button 
Author Message
 Treeview: Right Mouse Button

I have a tree control on a dialog box, which responds to the right mouse
button by displaying a popup-menu. However, if the right-mouse button is
clicked on an item which is not currently selected, the focus remains with
the previous item. Does anybody know of a way of changing the focus to the
item which the mouse right-clicked on?

Any advice will be very mcuh appreciated (after 6 hours on the problem).

Cheers

Matt

-------------------------------------------
Matt Cooling


http://www.*-*-*.com/



Sat, 15 Dec 2001 03:00:00 GMT  
 Treeview: Right Mouse Button
In the OnContextMenu method you should check whether user right-clicked
mouse or pressed the context menu key on the keyboard. If the context menu
was activated by a right-click, you have to figure out, what item was hit
(TreeView_HitTest) and then select it (TreeView_SelectItem) before showing
menu.

Oleg


Quote:
> I have a tree control on a dialog box, which responds to the right mouse
> button by displaying a popup-menu. However, if the right-mouse button is
> clicked on an item which is not currently selected, the focus remains with
> the previous item. Does anybody know of a way of changing the focus to the
> item which the mouse right-clicked on?

> Any advice will be very mcuh appreciated (after 6 hours on the problem).

> Cheers

> Matt

> -------------------------------------------
> Matt Cooling


> http://i.am/mcooling/



Sat, 15 Dec 2001 03:00:00 GMT  
 Treeview: Right Mouse Button

Quote:

> I have a tree control on a dialog box, which responds to the right mouse
> button by displaying a popup-menu. However, if the right-mouse button is
> clicked on an item which is not currently selected, the focus remains with
> the previous item. Does anybody know of a way of changing the focus to the
> item which the mouse right-clicked on?

Here's some code that works for me (in an OnRclick handler in a CTreeView):

        CPoint pt(::GetMessagePos ());
    ScreenToClient(&pt);

        CTreeCtrl& theTree = GetTreeCtrl();

        // find item they clicked on
        TV_HITTESTINFO hitTest;
        memset(&hitTest, 0, sizeof(TVHITTESTINFO));
        hitTest.pt = pt;
    theTree.HitTest(&hitTest);

        // if found one
    if (hitTest.flags & LVHT_ONITEM)
        {
                // select that item & notify document of change
                VERIFY(theTree.SelectItem(hitTest.hItem));

                //... specialized view code omitted for clarity

                // now do the context menu
                CRect rect;
                theTree.GetItemRect(hitTest.hItem, &rect, TRUE);
                ClientToScreen(rect);
                CPoint point(rect.left, rect.bottom);
                OnContextMenu(this, point);
    }

Jim [VC/MFC MVP]
To send mail, change spam-me-not to msn



Sat, 15 Dec 2001 03:00:00 GMT  
 Treeview: Right Mouse Button

Quote:
>I have a tree control on a dialog box, which responds to the right mouse
>button by displaying a popup-menu. However, if the right-mouse button is
>clicked on an item which is not currently selected, the focus remains with
>the previous item. Does anybody know of a way of changing the focus to the
>item which the mouse right-clicked on?

Matt,

I assume you're trying to simulate the effect that Explorer gives
where it temporarily switches to the item you've right clicked on. If
so, have a look on http://www.mvps.org/vcfaq/, there's an example
there on handling WM_CONTEXTMENU that illustrates how I achieved a
similar effect.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sat, 15 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. [Fwd: Right mouse button and depressed button]

2. How to use the right and middle mouse buttons

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

4. Right mouse button click in CTreeView?

5. Toggling the mouse buttons from right to left

6. Selection in tree with right mouse button

7. Select Listbox item by right (!)mouse button pressing

8. Pop up menu has my program (Right Mouse Button)

9. Right button mouse click in CListBox

10. CListBox and Right Mouse button

11. Overwriting Right Mouse Button click of edit boxes

12. Popup menu clicking the right mouse button

 

 
Powered by phpBB® Forum Software