Use pop-up menus (POPMENU)
Pop-up menu (POPMENU) Everyone is familiar, where the mouse button pops up on the Win98 desktop is the pop-up menu. Typically, pop-up menus are popped up when the mouse button is clicked, of course, can also be ejected at any time as needed. In the MFC of VC 5, the class named cmenu is called CMenu. Below I introduce you to the basic method of establishing a pop-up menu.
1. Create a menu resource in the resource editor to create a new menu resource, such as the ID number of the menu is IDC_POPMENU. This menu has two layers, which has a pop-up menu item, and this menu item is the content of the pop-up menu that will be created. As for the message mapping of each menu item, the same as the general menu. Second, using the CMenu class object CMenu class member function, but establishing pop-up menus only need to use several member functions. 1, loadMenu function
Function: Load menu resource prototype from the application's executable: BOOL LoadMenu (uint nidResource); where NidResource is the ID number of the menu resource, here is the original IDC_POPMENU. 2, getSubMenu function
Function: This function is used to get a pointer to the submenu. Prototype: cmenu * getSubmenu (int NPOS) const; npos is a layer, 0 is the first layer menu ... With this type. Since we need the first layer of the first layer of the "bullets", you can get the class pointer to the first layer menu with GetSubMenu (0). 3, TRACKPOPUPMENU function
Function: Display the pop-up menu in the specified location and track the selected key: BOOL TRACKPOPUPMENU (Uint NFLAGS, INT X, INT Y, CWND * PWND, LPCRect LPRECT = NULL); where: NFLAGS is the screen coordinate property and mouse coordinate properties Screen coordinate properties: TPM_CENTERALIGN Landscape Menu TPM_LEFTALIGN translators in X left align TPM_RightAlign horizontally landscape with x right alignment mouse button attribute (only when responding to WM_CONTEXTMENU messages): TPM_LEFTBUTTON continuously press? Right button does not pop up menu Right-click the selected menu item TPM_RightButton continuously pressing the mouse to pop up the menu, the mouse button can be used for the selected menu item x, y is the area of the screen coordinate LPRECT menu. If null, when the user presses the mouse button outside the menu, the menu will disappear three, and the specific implementation method
Add the response function of the NM_RClickT message with the "Add Windows Message Handler" feature in ClassWizard, the code is as follows, the comment is very detailed, the debugging in the VC6 Win2000 environment is successful, everyone is interested in trying yourself:
Void ClistCtrltestdlg :: OnRclickList1 (NmHDR * PNMHDR, LRESULT * PRESULT) {// Todo: Add Your Control Notification Handler Code Here
CListCtrl * clist = (clistctrl *) getdlgitem (idc_list1); // Get pointer cmenu menu, * psubmenu; // define the cMenu object Menu.LoadMenu (iDR_PopMenu) you want to use; // Load customized Right-click menu psubmenu = menu.getsubmenu (0); // Get the first pop-up menu, so the first menu must have submenu cpoint opoint; // Define a location for determining the cursor position getCursorpos (& Opoint); // Get the location of the current cursor so that the menu can follow the cursor int = clist-> getSelectionMark (); // Store the currently selected in the current selected in the current CSTRING PSTRING = CLIST-> GetItemText (ISTAT, 0); // Get the data in the current item, 0 representatives are the 0rin // pstring = "Your selected item is:" pstring; // Display current selection // messageBox (pstring); // Display the currently selected path PSUBMENU- > TRACKPOPUPMENU (TPM_LEFTALIGN, OPOINT.X, OPOINT.Y, THIS); // Display pop-up menu in the specified location * PRESULT = 0;