On the right-click menu problem

Category: VC/MFC -> UI Author: amber1234 Date: 2002-12-29 08:20:58
 
amber1234
2002-12-29 08:20:58
TreeCtrl want to achieve in the context menu , but you can not get the right point in the current node
getSelectedItem achieved is left selected node
so you must first select with the left and then right click
can directly obtain the right point in

node Thank
mumu0725
2002-12-29 08:36:48
BEGIN_MESSAGE_MAP (CMyTreeCtrl,   CTreeCtrl)
// {{AFX_MSG_MAP (CMyTreeCtrl)
ON_NOTIFY_REFLECT (NM_RCLICK,   OnRClick)
ON_WM_CONTEXTMENU ()
//}} AFX_MSG_MAP
END_MESSAGE_MAP ()

void   CMyTreeCtrl :: OnRClick (NMHDR *   pNMHDR ,   LRESULT *   pResult)  
{
TRACE0 (" CMyTreeCtrl :: OnRClick () \ n ");
//   Send   WM_CONTEXTMENU   to   self
SendMessage (WM_CONTEXTMENU,   (WPARAM)   m_hWnd,   GetMessagePos ());
//   Mark & ​​nbsp; message   as   handled   and   suppress   default   handling
* pResult   =   1;
}

void   CMyTreeCtrl :: OnContextMenu (CWnd *   pWnd,   CPoint   ptMousePos)  
{
//   if   Shift-F10
if   (ptMousePos.x   ==   -1   & &   ptMousePos.y   ==   -1)
ptMousePos   =   (CPoint)   GetMessagePos ();

ScreenToClient (& ptMousePos);

UINT   uFlags;
HTREEITEM   htItem;

htItem   =   HitTest (  ptMousePos,   & uFlags  );

if (  htItem   ==   NULL  )
return;

m_hActiveItem   =   htItem;

CMenu   menu;
CMenu *   pPopup;

//   the   font   popup   is   stored   in   a   resource
menu.LoadMenu (IDR_TREEITEM_CONTEXTMENU);
pPopup   =   menu.GetSubMenu (0);
ClientToScreen ( & ptMousePos);
pPopup- > TrackPopupMenu (  TPM_LEFTALIGN,   ptMousePos.x,   ptMousePos.y,   this  );
}
chen_hsin_cheng
2002-12-29 08:54:27
Ctrl + W   [ class Wizard ]
NM_RCLICK find IDC_LIST1 then find the right Message box.
Double-click Add message , add your Pop menu.
z_zshan
2002-12-29 09:07:36
according to the mouse position , with CTreeCtrl :: HitTest get node
maogeruge
2002-12-29 09:14:21
Thank you, I do not know LZ solve No, I was resolved, ha ha , thank you upstairs