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);
}