Menu – Giavapps Windows API

 

 

api_menu_create() Creates a menu bar. The menu is initially empty. If the function succeeds, the return value is a MenuHandle. If the function fails, the return value is false.

 

api_menu_add_submenu(MenuHandle, Position, Text) Adds a drop-down menu or submenu menu to the given menu bar. The function returns the SubMenuHandle.

MenuHandle: it must be a MenuHandle.
Position: the position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.
Text: text of the sub menu.

 

api_menu_add_item(MenuHandle, Position, NextBitmapHandle, Text) Adds a menu item as a text string to the to the specified drop-down menu, submenu, or shortcut menu. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

MenuHandle: it must be a MenuHandle.
NextBitmapHandle: the bitmap shown next to the item. Set this argument to false if you don’t want any bitmap image.
Text: text of the menu item.

 

api_menu_add_item_bitmap(MenuHandle, Position, NextBitmapHandle, BitmapHandle) Adds a menu item as a bitmap to the specified drop-down menu, submenu, or shortcut menu. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

MenuHandle: it must be a MenuHandle.
Position: the position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.
NextBitmapHandle: the bitmap shown next to the item. Set this argument to false if you don’t want any bitmap image.
BitmapHandle: it must be a BitmapHandle.

 

api_menu_add_item_bar_break(MenuHandle, Position) Adds a new item and places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) separating columns by a vertical line. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

MenuHandle: it must be a MenuHandle.
Position: the position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

api_menu_add_item_break(MenuHandle, Position) Adds a new item and places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without separating columns. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

MenuHandle: it must be a MenuHandle.
Position: the position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

api_menu_add_item_separator(MenuHandle,Position) Adds a new item as a horizontal dividing line to the specified drop-down menu, submenu, or shortcut menu. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

MenuHandle: it must be a MenuHandle.
Position: the position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

api_menu_set_item_enabled(MenuHandle, ItemIndex, Enabled) Enables or disables the specified menu item. The return value specifies the previous state of the menu item. If the menu item does not exist, the return value is -1.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.
Enabled: disabled (false) or enabled (true).

 

api_menu_get_item_enabled(MenuHandle, ItemIndex) This function returns true if the menu item is enabled or false otherwise.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.

 

api_menu_set_item_checked(MenuHandle, ItemIndex, Checked) Sets the state of the specified menu item’s check-mark attribute to either selected or clear. The return value specifies the previous state of the menu item. If the menu item does not exist, the return value is -1.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.
Checked: unchecked (false) or checked (true).

 

api_menu_get_item_checked(MenuHandle, ItemIndex) This function returns the state of the specified menu item’s check-mark attribute to either unchecked (false) or checked (true).

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.

 

api_menu_set_item_default(MenuHandle, ItemIndex) Sets the default menu item for the specified menu.

MenuHandle: it must be a MenuHandle.
ItemIndex: item index or use -1 for no default item.

 

api_menu_get_item_default(MenuHandle) Returns the ItemIndex of the default menu item. If the function fails, the return value is -1.

MenuHandle: it must be a MenuHandle.

 

api_menu_set_item_right_order(MenuHandle, ItemIndex, RightOrder) Specifies that menus cascade right-to-left (the default is left-to-right). This is used to support right-to-left languages, such as Arabic and Hebrew.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.
RightOrder: sets right order (true) or removes right order (false).

 

api_menu_get_item_right_order(MenuHandle, ItemIndex) This function returns true when the given menu item has right order or false otherwise.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.

 

api_menu_set_item_bitmaps(MenuHandle,ItemIndex,UncheckedBitmapHandle, CheckedBitmapHandle) Associates the specified bitmaps with a menu item. Whether the menu item is selected or clear, the system displays the appropriate bitmap next to the menu item. If the function succeeds, the return value is true. If the function fails, the return value is false.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.
UncheckedBitmapHandle: the bitmap shown when the submenu item is unchecked.
CheckedBitmapHandle: the bitmap shown when the submenu item is checked.

 

api_menu_get_item_clicked(MenuHandle, ItemIndex) This function returns true when the user clicks on the specified item or false otherwise.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.

 

api_menu_get_item_command(MenuHandle, ItemIndex) Retrieves the menu item identifier of a menu item located at the specified position in a menu. If the menu item identifier is NULL or if the specified item opens a submenu, the return value is -1.

MenuHandle: it must be a MenuHandle.
ItemIndex: index of the menu item.

 

api_menu_get_item_count(MenuHandle) Returns the number of items in the specified menu of submenu. If the function succeeds, the return value specifies the number of items in the menu. If the function fails, the return value is -1.

MenuHandle: it must be a MenuHandle.

 

api_menu_delete_item(MenuHandle, Position) Deletes an item from the specified menu or submenu. If the menu item opens a menu or submenu, this function destroys the handle to the menu or submenu and frees the memory used by the menu or submenu. If the function succeeds, the return value is true. If the function fails, the return value is false.

MenuHandle: it must be a MenuHandle.
Position: position of the menu item.

 

api_menu_show(WindowHandle, MenuHandle, X, Y, Flags) Displays a shortcut menu at the specified location and tracks the selection of items on the menu. The shortcut menu can appear anywhere on the screen.

WindowHandle: it must be a WindowHandle.
MenuHandle: it must be a MenuHandle.
X: The horizontal location of the shortcut menu, in screen coordinates.
Y: The vertical location of the shortcut menu, in screen coordinates.
Flags: Flags of the menu. Flags must be separated with the symbol "|".

Flags can be zero of more of these flags to specify function options.

Use one of the following flags to specify how the function positions the shortcut menu horizontally.

TPM_CENTERALIGN Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter.

TPM_LEFTALIGN Positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter.

TPM_RIGHTALIGN Positions the shortcut menu so that its right side is aligned with the coordinate specified by the x parameter.

Use one of the following flags to specify how the function positions the shortcut menu vertically.

TPM_BOTTOMALIGN Positions the shortcut menu so that its bottom side is aligned with the coordinate specified by the y parameter.

TPM_TOPALIGN Positions the shortcut menu so that its top side is aligned with the coordinate specified by the y parameter.

TPM_VCENTERALIGN Centers the shortcut menu vertically relative to the coordinate specified by the y parameter.

Use the following flags to control discovery of the user selection without having to set up a parent window for the menu.

TPM_NONOTIFY The function does not send notification messages when the user clicks a menu item.

TPM_RETURNCMD The function returns the menu item identifier of the user’s selection in the return value.

Use one of the following flags to specify which mouse button the shortcut menu tracks.

TPM_LEFTBUTTON The user can select menu items with only the left mouse button.

TPM_RIGHTBUTTON The user can select menu items with both the left and right mouse buttons.

 

api_menu_redraw(WindowHandle) Redraws the menu bar of the specified window. If the menu bar changes after the system has created the window, this function must be called to draw the changed menu bar. If the function succeeds, the return value is true. If the function fails, the return value is false.

WindowHandle: it must be a WindowHandle.

 

api_menu_delete(MenuHandle) Deletes the specified menu and frees any memory that the menu occupies. If the function succeeds, the return value is true. If the function fails, the return value is false. Before closing, an application must use the api_menu_delete() function to destroy a menu not assigned to a window. A menu that is assigned to a window is automatically destroyed when the application closes. api_menu_delete() is recursive, that is, it will destroy the menu and all its submenus.

MenuHandle: it must be a MenuHandle.

 

Code Examples

 

Creating a Menu

 

//MENU
menu = api_menu_create();
menu_file = api_menu_add_submenu(menu,-1,"File");
menu_edit = api_menu_add_submenu(menu,-1,"Edit");
menu_help = api_menu_add_submenu(menu,-1,"Help");
//FILE
menu_file_new = api_menu_add_item(menu_file,-1,0,"New…");
menu_file_save = api_menu_add_item(menu_file,-1,0,"Save…");
menu_file_saveas = api_menu_add_item(menu_file,-1,0,"Save As…");
//EDIT
menu_edit_undo = api_menu_add_item(menu_edit,-1,0,"Undo");
menu_edit_redo = api_menu_add_item(menu_edit,-1,0,"Redo");
api_menu_add_item_separator(menu_edit,-1);
menu_edit_cut = api_menu_add_item(menu_edit,-1,0,"Cut");
menu_edit_copy = api_menu_add_item(menu_edit,-1,0,"Copy");
menu_edit_paste = api_menu_add_item(menu_edit,-1,0,"Paste");
//HELP
menu_help_contents = api_menu_add_item(menu_help,-1,0,"Contents…");
menu_help_about = api_menu_add_item(menu_help,-1,0,"About Application…");

 

Checking Clicks

 

Step Event:

 

//FILE
if(api_menu_get_item_clicked(menu_file,menu_file_new))
{
api_messagebox(window,"FILE > NEW","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_file,menu_file_save))
{
api_messagebox(window,"FILE > SAVE","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_file,menu_file_saveas))
{
api_messagebox(window,"FILE > SAVE AS","INFO",MB_OK);
}
//EDIT
else if(api_menu_get_item_clicked(menu_edit,menu_edit_undo))
{
api_messagebox(window,"EDIT > UNDO","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_edit,menu_edit_redo))
{
api_messagebox(window,"EDIT > REDO","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_edit,menu_edit_cut))
{
api_messagebox(window,"EDIT > CUT","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_edit,menu_edit_copy))
{
api_messagebox(window,"EDIT > COPY","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_edit,menu_edit_paste))
{
api_messagebox(window,"EDIT > PASTE","INFO",MB_OK);
}
//HELP
else if(api_menu_get_item_clicked(menu_help,menu_help_contents))
{
api_messagebox(window,"HELP > CONTENTS","INFO",MB_OK);
}
else if(api_menu_get_item_clicked(menu_help,menu_help_about))
{
api_messagebox(window,"HELP > ABOUT","INFO",MB_OK);
}

 

Showing a Context Menu

 

Step Event

 

if(api_window_get_clicked(window,mb_right))
{
var command = api_menu_show(window,menu_edit,display_mouse_get_x(),display_mouse_get_y(),TPM_RETURNCMD);

//CHECKING USER SELECTION

if
(command == api_menu_get_item_command(menu_edit,menu_edit_undo))
{
api_messagebox(window,"EDIT > UNDO","INFO",MB_OK);
}
else if(command == api_menu_get_item_command(menu_edit,menu_edit_redo))
{
api_messagebox(window,"EDIT > REDO","INFO",MB_OK);
}
else if(command == api_menu_get_item_command(menu_edit,menu_edit_cut))
{
api_messagebox(window,"EDIT > CUT","INFO",MB_OK);
}
else if(command == api_menu_get_item_command(menu_edit,menu_edit_copy))
{
api_messagebox(window,"EDIT > COPY","INFO",MB_OK);
}
else if(command == api_menu_get_item_command(menu_edit,menu_edit_paste))
{
api_messagebox(window,"EDIT > PASTE","INFO",MB_OK);
}
}

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Leave a Reply

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

*