| Header file: | menus.h |
| Object name: | fMAINMENU |
| Object index: | 1 of 2 Objects (the other is fPOPUPMENU) |
This class is designed to allow you to build menus on the fly or load them from resources and apply this menu to a window. With this class, a menu is the menu at the top of the window (ie. File, Edit, Help, etc).
Ordinarily, I would put some sample code on these pages, but programming menus is a little more advanced than what I can show in an example. For that reason, please refer to the bit about menus in the Learning the F3C page.
| Prototype | Description |
| HMENU GetHandle(void); | This function returns the handle to the menu, which you may wish to use when calling certain functions. |
| void AddPopup(HMENU Popup, char* Name); | This function adds a 'popup' menu to the set of menus that you are currently working on. You would need to add a 'File' popup menu before you can make a file menu, for example. When you click 'File', the popup menu that you specifed will be displayed. You may like to use the fPOPUPMENU object to first build your popup menu, and then get the handle from that menu to call this function. If you don't understand anything I've just written, then please look at the sample source code to see an example of how this works. |
| void RemovePopup(HMENU Popup); | This function reverses the action done by the above function. You will need to pass a handle to a menu - the handle to the menu that you wish to remove. |
| void AddItem(char* Caption, int ID); | This function adds an item to the current menu. Please note that adding an item to the main menu will simply add a menu that does not drop down, but responds by simply clicking it. The ID is a number that uniquely identifies the menu, and Caption is what the name of the item is. |
| void InsertItem(char* Caption, int ID, int InsertBefore); | This function works just like the AddItem() function, except that it inserts a menu item before the index of the item that you specify with InsertBefore. Please note that InsertBefore is actually an index, not an ID. The first item on the menu will be item 0 (Zero). |
| void ModifyItem(int ID, char* Caption); | This function modifies the caption of a menu item. You will need to specify the ID number that you gave that item when you originally added it. |
| void RemoveItem(int ID); | This function removes an item from the menu. The item specified by ID will be removed. |
| void ApplyMenu(HWND Window); | This function applies the menu to the window specified by Window. This menu will then appear at the top of the window. |
| void UnApplyMenu(HWND Window); | This function removes the menu from the given window. |
| void UpdateMenu(HWND Window); | If you change your menu, you may wish to refresh it, and it is a lot faster to refresh the menu with this function rather than to remove the menu and re-apply it. |
| void ResetMenu(void); | This function destroys the menu completely, but does not un-apply it from a window. You may like to un-apply the menu first, before you destroy it. |
| void LoadPremadeMenu(char* cID, int ID); | This function loads a menu from the current programs resource file. You can either pass the name of the menu or the ID to this function, but for whichever one you do not use, pass NULL or 0 (Zero) (respectively). |
| void LoadPremadeMenu(HINSTANCE Instance, char* cID, int ID); | This function is just like the above function, except for the fact that it takes an extra parameter. The extra parameter, Instance, refers to another module from which the menu is to be loaded from. For instance, you may like to load a DLL, and then read a menu from that. |
| bool CheckID(WPARAM wParam, int ID); | You can call this function from wherever you check your menu events to find if the menu item with the specified ID was activated. However, all that this function does is check to see if wParam equals ID, so you may like to dispense with this function and simply check the ID manually. For an advanced explanation of how the menu events work, please see the sample code section. |
Ordinarily, I would put some sample code here, but programming menus is a little more advanced than what I can show in an example. For that reason, please refer to the bit about menus in the Learning the F3C page.
| Back to index | The FreeFoote Foundation Classes Documentation |