Objective Grid: Displaying a dialog or popup-menu when the user clicks the right mouse button

Article ID: 708
Last updated: 11 Jun, 2018
Article ID: 708
Last updated: 11 Jun, 2018
Revision: 3
Views: 1687
Posted: 23 Jan, 2001
by Meltreger B.
Updated: 11 Jun, 2018
by Meltreger B.

Problem


How can I display a dialog or popup-menu when the user clicks the right mouse button?


Cause



Action


You should override the OnRButtonClickedRowCol() method and call TrackPopupMenu().

Example:

BOOL CMyGridCtrl::OnRButtonClickedRowCol(ROWCOL nRow, ROWCOL nCol, UINT nFlags, CPoint pt)
{
// unreferenced parameters
nRow, nCol, nFlags;

CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP_GRID_CONTROL));

CMenu* pPopup = menu.GetSubMenu( 0 );
ASSERT( pPopup != NULL );

CWnd* pWndPopupOwner = AfxGetMainWnd( );

// display the menu
ClientToScreen(&pt);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, pWndPopupOwner);

// we processed the message
return TRUE;

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 708
Last updated: 11 Jun, 2018
Revision: 3
Views: 1687
Posted: 23 Jan, 2001 by Meltreger B.
Updated: 11 Jun, 2018 by Meltreger B.

Others in this category