Getting Started with Win32 development (4) Creating menus

Source: Internet
Author: User

We certainly know, now, in the actual development will certainly not like me to write Win32 program, you see, even a WinMain to n line of code. But many people do not understand what is called learning, what is called exploration. In fact, the skills that are usually used in actual development only account for less than 20% of our understanding of the objective world, so if you are interested in calculating, an estimated 80% of the knowledge you do not know where to go. Even if we do not put the WIN32 program into practice in the future, however, if you know this, you will find that many times it is helpful to us.

Even if just a simple understanding of some of the principles of Win32, I believe that the future of programming learning and growth, is beneficial.

In order to improve the effect of fraught, I said a few paragraphs F, the following start today's topic.

To add a menu to a window, of course you might be able to work out the n methods, but here I say two, one is quite complex, the other is slightly simpler.

Method One, add a menu with code

The idea of this approach is to first define a HMENU variable in the global scope to hold the handle to the menu bar in the window, and the root menu (menu bar) can be created by the CreateMenu function, which can then be used AppendMenu function or Insertmenuitem function to create a menu item.

The handle is the ID of various resources in memory, such as icons, pictures, strings, and so on. Our menu is also a resource.

I wrote a function to create the menu dynamically.

void Createmymenu ()     
{     
    hroot = CreateMenu ();     
    if (!hroot) return     
        ;     
    Hmenu POP1 = CreatePopupMenu ();     
    AppendMenu (Hroot,     
        mf_popup,     
        (uint_ptr) pop1,     
        L "operation");     
    One method is to use the AppendMenu function     
    appendmenu (POP1,     
        mf_string,     
        idm_opt1,     
        L "aircraft");     
         
    Another method is to use the Insertmenuitem function to     
    menuiteminfo MIF;     
    mif.cbsize = sizeof (menuiteminfo);     
    MIF.CCH = m;     
    Mif.dwitemdata  = NULL;     
    Mif.dwtypedata = L "machine gun";     
    Mif.fmask = miim_id | miim_string | Miim_state;     
    Mif.fstate = mfs_enabled;     
    Mif.ftype = miim_string;     
    Mif.wid = Idm_opt2;     
         
    Insertmenuitem (POP1,IDM_OPT2,FALSE,&MIF);     
         
}

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.