1. First, create the menu to be used in the menu item in the resource bar;
2. for common windows and controls, you can use classwizard to create its message processing function oncontextmenu ();
3. You can also right-click a menu in a specific area to create a message response;
4. In the message response function, the menu is displayed:
Void cscanfilelist: oncontextmenu (cwnd */* pwnd */, cpoint point)
{
// Todo: add your message handler code here
// Right-click to display the menu
Cmenu menu;
Menu. loadmenu (idr_mainframe );
Cmenu * ppopupmenu = menu. getsubmenu (1 );
// Show menu
Ppopupmenu-> trackpopupmenu (tpm_leftalign, point. X, point. Y, afxgetmainwnd ());
}
5. If you are right-clicking a response message, you must use the API to obtain the position parameter of the pop-up menu. That is, you must obtain the current cursor position:
Case wm_rbuttondown:
Point pt;
If (! Getcursorpos (& pt ))
{
// Error
Cstring strerr;
Strerr. Format (_ T ("cannot pop mouse right button MEMU, getcursorpos failed! /R/n/R/nerror: % s ")
, Geterrormsgandcode () // for this function, see my other article: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 2071783
);
Afxmessagebox (strerr );
Return;
}
Cmenu rbmenu;
Rbmenu. loadmenu (idr_menu_rbutton );
Cmenu * ppopupmenu = rbmenu. getsubmenu (0 );
Ppopupmenu-> trackpopupmenu (tpm_leftalign, Pt. X, Pt. Y, this );
Break;
6. That's all. (PS: If you are free, please reply to me! :)