Add a Right-Button ListBox class or library to your project. Next add a rightbutton handler to the window containing your ListBox. The following boiler plate code for popup menu is all that is needed.
void MyWindow::EvRButtonDown (uint modKeys, TPoint& point)
{
TDialog::EvRButtonDown(modKeys, point);
// INSERT>> Your code here.
TMenu menu(HWindow);
HMENU hMenu = menu.GetSubMenu(0); // 0 is the first menu of this window,
// 1 would be the second etc.
TPopupMenu popupMenu(hMenu); // Create the Menu
GetCursorPos(point); // Put the menu at the click point
popupMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point,0,HWindow);
}
When the user presses the right button, a menu will pop up in the current window and when the button is released, the command selected is executed.
Sometimes you want to create a popup menu that is not one of those used by the window. the following example shows how to create such a menu. In this example, each of the cm commands must be defined as identifiers in the resource editor and must be tied to handlers in the response table.
void InventoryDlg::EvRButtonDown (uint modKeys, TPoint& point)
{
TDialog::EvRButtonDown(modKeys, point);
// INSERT>> Your code here.
//::EvLButtonDblClk(modKeys, point);
GetCursorPos(point);
TPopupMenu rClickMenu;
rClickMenu.AppendMenu(MF_STRING,CM_ORDER_ITEM,"&Order Item");
rClickMenu.AppendMenu(MF_STRING,CM_PRICE_ITEM,"&Price Item");
rClickMenu.AppendMenu(MF_STRING,CM_ADD_INVENTORY,"&Add Inventory");
rClickMenu.AppendMenu(MF_STRING,CM_CHANGE_PRICE,"&Change Price");
rClickMenu.AppendMenu(MF_SEPARATOR,0,(LPSTR)0);
rClickMenu.AppendMenu(MF_STRING,CM_NEW_ITEM,"&New Item");
rClickMenu.AppendMenu(MF_STRING,CM_DELETE_ITEM,"&Delete Item");
rClickMenu.AppendMenu(MF_STRING,CM_LIST_REORDER,"List &Reorders");
rClickMenu.AppendMenu(MF_STRING,CM_FIND,"&Find");
rClickMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON,point,0,*this);
}