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.
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
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