mfc >> Add popup menu to a CTreeView?

by ShipHead » Thu, 27 Jan 2005 06:33:30 GMT

How do I add a popup menu to a CTreeView, such that when I right
click on a node a pop menu appears?

TIA.
B.




mfc >> Add popup menu to a CTreeView?

by Ajay Kalra » Thu, 27 Jan 2005 10:27:34 GMT


Handle NM_RCLICK in your control. For sample code, look at
codguru/codeproject.

--
Ajay Kalra (MVP - VC++)
XXXX@XXXXX.COM









mfc >> Add popup menu to a CTreeView?

by Johnny » Fri, 28 Jan 2005 02:29:31 GMT




the MFC sample 'daoview' contains an example of what you want.
See in there the method
CDaoTreeView::OnRightClick(




Add popup menu to a CTreeView?

by ShipHead » Mon, 31 Jan 2005 03:37:16 GMT





I've added the method:

void CMyDlg::OnRightClick(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}

I added this to the message map of the class.

ON_NOTIFY_REFLECT(NM_RCLICK, OnRightClick)


My question is:
I am writing a Dialog based application.
How do you differentiat between a right click on the dialog
vs a right click on the CTreeView?

Because right now I'm not gettting the call to my method.






Similar Threads

1. Adding a conext menu to CTreeView

Hi,
everything seems to be OK with your code.
There is my (working) snippet:
void CProjectView::OnNMRclick(NMHDR* /*pNMHDR*/, LRESULT *pResult)
{
  CPoint pt;
  CTreeCtrl &tree = GetTreeCtrl();
  GetCursorPos(&pt);
  tree.ScreenToClient(&pt);
  HTREEITEM h = tree.HitTest(pt);
  if(h)
  {
    tree.SelectItem(h);
    tree.SendMessage(WM_CONTEXTMENU, (WPARAM)tree.GetSafeHwnd(),
MAKELPARAM(pt.x, pt.y));
  }
  *pResult = 0;
}


"Ori" < XXXX@XXXXX.COM > wrote in message news: XXXX@XXXXX.COM ...
> Hi.
>
> I'm trying to add a context menu capability to a CTreeView after a right
> click on an item in it.
>
> In order to do this - i'm getting a notification from the tree control on
a
> right click and trying to figure whether the click was on an item or not:
>
> void CLeftView::OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult)
> {
>
>     LPNMTREEVIEW lpNMTV = (LPNMTREEVIEW) pNMHDR;
>
>     TVITEM item = lpNMTV->itemOld;    // This is ALWAYS NULL (itemNew too)
>
>     CPoint pos = lpNMTV->ptDrag;        // This is ALWAYS the same wrong
> coordinate
>
>     GetCursorPos(&pos);
> // and in this way
>
>     GetTreeCtrl().ScreenToClient(&pos);
>
>     UINT uFlags;
>
>     HTREEITEM hItem = GetTreeCtrl().HitTest(pos, &uFlags);            // i
> always get hItem = NULL
>
>     if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)                //
and
> i never pass this check :(
>
>     {
>         // My code here
>     }
>     *pResult = 0;
> }
>
> Will gladly accept suggestions....
> Ori
>
>
>


2. adding right-click popup menu to windows form - CSharp/C#

3. Add a PopUp Menu to a new DBGrid.

Hi, I want to create my own DBGrid and add it a PopUp Menu.
I used the following code.
If I put just one TSGDBGrid in the form work fine but if I
put more thant one an exception is generated saying that
"SGPopUp already exist"
What can I do to avoid this. Thanks.

constructor TSGDBGrid.create(AOwner: TComponent);
var menItm : TMenuItem;
begin
  inherited Create(AOwner);
  if (csdesigning in ComponentState) then
  begin
   Self.Color := clCream;
   Ctl3D := False;
  end
  else
  begin
    men := TPopupMenu.Create(AOwner);
    menItm := TMenuItem.Create(menu);
    menItm.Name := 'MenItem';
    men.Name := 'SGPopUp';
    men.Items.Add(menItm);
    SGPopUp := men;
  end
end;

destructor TSGDBGrid.Destroy;
begin
  Inherited Destroy;
end;

------------------------
S.L.

4. Display a Popup menu from a Popup - (Part 2)

5. Popup Menu - how do I popup again after selection

I have a popup menu from a right click on a TImage. This menu
is dynamically generated and contains many submenus. How can I
re-open this menu automatically after someone picks a menuitem?

For example, let's say the menu has the following:

Item 1
---Sub Item 1
------Sub Sub Item 1
---Sub Item 2
------Sub Sub Item 1
---Sub Item 3
------Sub Sub Item 1
------Sub Sub Item 2
------Sub Sub Item 3

The user selects Item 1 -> Sub Item 3 -> Sub Sub Item 3

I want the menu to popup again with Item 1 -> Sub Item 3 selected
and open.

Thanks.

6. can I auto expand sub menu for a popup menu control

7. Context menu or Popup menu

hi

how can i create a context menu (like the ones that pop up when you do a
right click) in mfc?
i've found some sample code and added this to my application but it doesn't
work:

void CCAC_SERVERDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
 CMenu menu;

 menu.LoadMenu(IDR_POPUP_MENU);

 CMenu* pContextMenu = menu.GetSubMenu(0);

 pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd(), NULL);

}
I've created the IDR_POPUP_MENU in the ressource editor.
the programm crashes at the pContextMenu->TrackPopupMenu(....) line.

thanks for your help
Urban


8. Systray popup menu overlaps with Windows systray menu