MFC dynamic Menu

Source: Internet
Author: User
Tags textout

1.cmenu3view Keyboard Get function parsing

1 voidCmenu3view::onchar (UINT NChar, uint nrepcnt, uint nflags)2 {4CCLIENTDC DC ( This);//gets the view handle5         if(0x0d==nchar)//If the ENTER key is detected6         {7              if(0==++m_nindex)//The initial value is-1, which indicates the first carriage return8              { 9M_menu. CreatePopupMenu ();//Create a menuTenGetParent ()->getmenu ()->appendmenu (Mf_popup, (UINT) M_menu.m_hmenu/*Make a cast*/,"Phonebook");//window size has changed, just come out, what is the situation?  OneGetParent ()->drawmenubar ();//call the parent class to make the menu bar heavy A              } -M_menu. AppendMenu (Mf_string,idm_phone1+m_nindex/*Here's the highlight .*/, M_strline.left (M_strline.find (" "))); - M_strarray.add (m_strline); theM_strline.empty ();//press ENTER to clear -               -Invalidate ();//window re-operation -  +         } -       Else +       { Am_strline+= (Char) NChar; atdc. TextOut (0,0, m_strline); -       } -  - Cview::onchar (NChar, nrepcnt, nflags); -}

2. Tips for creating a code menu
First step: Add the ABC Add submenu to the Resource option, set its ID name
Step two: Add ID name and ID number in resource.h
Step three: Add the respective command window functions and delete
Fourth step: OnCommand mapping must be put out, because it has been deleted, can not be placed in the system custom area

1 Begin_message_map (Cmenu3view, CView)2 //{{Afx_msg_map (Cmenu3view)3 On_wm_char ()4 On_wm_cancelmode ()5 6 //}}afx_msg_map7 //Standard Printing Commands8 on_command (idm_phone1, OnPhone1)9 on_command (Idm_phone2, OnPhone2)Ten on_command (Idm_phone3, OnPhone3) One on_command (idm_phone4, OnPhone4) A on_command (Id_file_print, Cview::onfileprint) - on_command (Id_file_print_direct, Cview::onfileprint) - on_command (Id_file_print_preview, Cview::onfileprintpreview) theEnd_message_map ()

3. Understanding the message mechanism OnCommand can learn the message in advance

1 BOOL Cmainframe::oncommand (WPARAM WPARAM, LPARAM LPARAM)2 {3 intMenucmdid=loword (WParam);//get low by LoWord4Cmenu3view *pview= (Cmenu3view *) GetActiveView ();//This is the call of the view class in CMainFrame, which is implemented by creating a concrete object that needs to contain the header file5 //GetActiveView () is a CMainFrame related class6 if(Menucmdid>=idm_phone1 && menucmdid<idm_phone1+pview->m_strarray.getsize ())7 {8 //MessageBox ("Test");9CCLIENTDC DC (PView);//because the character array is in the view class, the DC (PView)Tendc. TextOut (0,0, Pview->m_strarray.getat (menucmdid-idm_phone1));//M_strarray is public One returntrue;//returns TRUE to no longer perform a view operation A } -  - returnCframewnd::oncommand (WParam, lParam); the}

MFC dynamic Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.