1. 程式人生 > >VS2008、VS2010、VS2012新增Pop-up Menu元件

VS2008、VS2010、VS2012新增Pop-up Menu元件

3、在OnContextMenu新增如下程式碼
 if (point.x == -1 && point.y == -1)
 {
  CRect rect;
  GetClientRect(rect);
  ClientToScreen(rect);
  point = rect.TopLeft();
  point.Offset(5, 5);
 }
 CMenu menu;
 VERIFY(menu.LoadMenu(CG_IDR_POPUP_TYPING_TEST_VIEW));        //CG_IDR_POPUP_TYPING_TEST_VIEW為選單ID
 CMenu* pPopup = menu.GetSubMenu(0);
 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);
}