| Header file: | menus.h |
| Object name: | fPOPUPMENU |
| Object index: | 2 of 2 Objects (the other is fMAINMENU) |
A popup menu is a menu that can be added to a main menu (the menu at the top of the window, those usually with 'File', 'Edit', and the rest of that lot) or simply asked to 'Popup' at a certain place on the screen. Either way, you'll find this menu a pretty useful item.
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 |
| void ExtractSubMenu(HMENU Handle, int Index); | This function obtains a popup menu from another menu (for example, a main menu), and stores that menu within this class. This can be useful for dissassembling menus that you previously put together. The first parameter is the menu to pull apart, and the second parameter is the index in the menu that you passed along where this popup menu occurs. You see? |
| void SetHandle(HMENU Handle); | This function makes this class take over control of the menu that you specify by Handle. Please note that whatever was currently in memory is destroyed and replaced with what you specify. You can then modify the menu with the functions provided by this class. |
| HMENU GetHandle(void); | This function returns the handle to the menu - which is useful for getting the menu's handle so that you can add it to a main menu. |
| void AddItem(char* Caption, int ID); | This function adds an item to the menu, with the caption specified by Caption and the ID specified by ID. |
| void AddCheckItem(char* Caption, int ID); | This function adds an item to the menu that has a check next to it (or at very least has the capability of displaying a check next to it). You can change the state of the check with the functions listed further down. |
| void AddColumnItem(char* Caption, int ID); | This function adds a new item, but adds it in a new column which is seperated from the last column by a vertical line. It looks a little weird, but can be quite useful. |
| void SetBitmaps(HBITMAP UnChecked, HBITMAP Checked, int ID); | This function sets the checked and unchecked bitmaps for a particular menu item. If you just want a static picture, try setting the same bitmap for both parameters. If you do not set bitmaps, then the default checks will be used. |
| void AddSeperator(void); | This function adds a seperator to the current menu. This seperator is in the form of a horizontal line on the menu. You can also add a seperator by adding a normal menu item, but setting the caption to a dash (-). |
| void AddPopupMenu(HMENU PopupMenuHandle, char* Caption); | This function adds a sub menu to the current menu. For example, you could create another fPOPUPMENU, and then append that to this menu. This then becomes a sub menu. |
| void InsertItem(char* Caption, int NewID, int InsertBefore); | This function inserts a menu item before the item specified by InsertBefore. Please note that InsertBefore is an index, and starts at 0 (Zero). |
| void InsertCheckItem(char* Caption, int NewID, int InsertBefore); | This function is just like the last function, except for the fact that it adds a check menu item instead (ie. an item that can be checked). |
| void InsertColumnItem(char* Caption, int NewID, int InsertBefore); | This function is just like the InsertItem() function, except for the fact that it inserts a new column as well as a new item. |
| void ModifyItem(int ID, char* Caption); | This function modifies an item's caption. You pass this function the ID of the item that you wish to change, and it will go and change the caption for you. Handy, huh? |
| void RemoveItem(int ID); | This function will remove the item in the menu that has the specified ID. Another handy-dandy function, that you are sure to use. |
| void RemoveSubMenu(HMENU Handle); | This function removes a submenu that you may have added earlier. You will need to pass the handle to the that menu to be able to remove it. |
| void LoadPremadeMenu(char* Name, int ID); | This function loads a menu from a resource file - the current program's resource file, to be exact. You can either specify the resources name or the resources ID - but not both. If you don't use the name, pass NULL for that, and if you don't use the ID, pass 0 (Zero) for that. |
| void LoadPremadeMenu(HINSTANCE Instance, char* Name, int ID); | This function is like the above function, except for the fact that you can specify what module to load the menu from. This might be handy if you wish to load a DLL and then load a menu from that. |
| void Enabled(bool Set, int ID); | This function sets whether or not a certain menu item is enabled or not. If the menu item is not enabled, it is greyed out, and you can not select that item. Pass TRUE for Set to make the item enabled, and FALSE to make the item disabled. ID should be an ID of one of the menu items. |
| bool Enabled(int ID); | This function determines whether or not a certain menu item is enabled or not. All you need to pass along is the ID of the item that you wish to check. The function will return TRUE if the item is enabled, or FALSE if it is not. |
| void Checked(bool Set, int ID); | This function sets whether a certain menu item is checked or not. Pass TRUE to make the item be checked, or FALSE to make the item un-checked. Please note that Windows does not automatically check and uncheck an item when it is clicked; you will need to intercept the clicks and manually set or un-set the check. You can use the next function to determine the current state of the check. |
| bool Checked(int ID); | This function finds out if the specified menu item is checked. It will return TRUE if the item is checked, or FALSE if it is not checked. If you want to, you can swap the check for a particular menu item by using the SwapCheck() function, as documented below. |
| void SwapCheck(int ID); | This function will swap the check for the specified item - ie, if the item is checked, it will be unchecked, and if it was unchecked, it will be checked. |
| void ResetMenu(void); | This function resets the contents of the menu completely. You can then go ahead and start adding items again, should you so wish. |
| void PopupMenu(int X, int Y, HWND WindowHandle); | This function displays the menu at the location (X,Y), and sends the messages from this menu to the window specified by WindowHandle, which is the assumed parent of the window. What you should probably do is just pass the handle of your main window for WindowHandle. Note that when you call this function, the menu will pop up just like a context menu - so that means that the menu is not attached to any window or anything. Right clicking on your system tray will show up a menu; this function has the same effect, and you can use it to show a menu when you intercept a right-click from the system tray. |
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 |