In VS2008, it is not possible to add pop-up menus as vc++6.0 through compnents and controls, which need to be added manually. You can create pop-up menus in two ways.
First, the use of existing menu resources to create
(1) First create a new menu resource under menu in Resource View.
(2) Then edit the new menu to look like the pop-up menu you want.
(3) Add the Wm_rbuttondown message to the CView class and add the following code in the message function Onrbuttondown ():
[Cpp]view plaincopyprint?
1 void Cmenuview::onrbuttondown (UINT nflags, CPoint Point)
2 {
3//TODO: Add the message Handler code here and/or call the default value
4
5//Create pop-up menu with existing menu resources
6 CMenu menu;
7 menu. LOADMENUW (IDR_MENU1); To load an existing menu resource
8 CMenu *ppopupmenu = menu. GetSubMenu (0); Get to create a good pop-up menu
9 ClientToScreen (&point); Converts the coordinates of the client area to the screen coordinates
//ppopupmenu->trackpopupmenu (Tpm_leftalign, Point.x, Point.y, GetParent ());
One Ppopupmenu->trackpopupmenu (tpm_leftalign | Tpm_rightbutton, Point.x, Point.y, this); Mouse Right click pop-up menu
12
Cview::onrbuttondown (nflags, point);
14}
void Cmenuview::onrbuttondown (UINT nflags, CPoint Point)
{
TODO: Add the message Handler code here and/or call the default value
Create a pop-up menu with existing menu resources
CMenu menu;
Menu. LOADMENUW (IDR_MENU1); To load an existing menu resource
CMenu *ppopupmenu = menu. GetSubMenu (0); Get to create a good pop-up menu
ClientToScreen (&point); Converts the coordinates of the client area to the screen coordinates
Ppopupmenu->trackpopupmenu (Tpm_leftalign, Point.x, Point.y, GetParent ());
Ppopupmenu->trackpopupmenu (Tpm_leftalign | Tpm_rightbutton, Point.x, Point.y, this); Mouse Right click pop-up menu
Cview::onrbuttondown (nflags, point);
}
Second, dynamically create pop-up menu
Creating a pop-up menu dynamically refers to the creation of a complete code type, adding the following code to the Wm_rbuttondown message:
[Cpp]view plaincopyprint?
void Cmenuview::onrbuttondown (UINT nflags, CPoint Point)
16 {
/TODO: Add Message Handler code here and/or invoke default values
18//Create pop-up menu dynamically
CMenu menu;
menu. CreatePopupMenu (); Create a pop-up menu
menu. APPENDMENUW (Mf_bycommand | Mf_string, Id_right_clear, _t ("Shear (&x)")); Add Child menu item
menu. APPENDMENUW (Mf_bycommand | Mf_string, Id_right_copy, _t ("Copy (&c)"));
The menu. APPENDMENUW (Mf_bycommand | Mf_string, Id_right_paste, _t ("Paste (&p)"));
menu. APPENDMENUW (Mf_separator);
menu. APPENDMENUW (Mf_bycommand | Mf_string, Id_right_clear, _t ("Clear \tctrl + C"));
ClientToScreen (&point); Converts the coordinates of the client area to the coordinates of the screen
27