Menu Class

 

 

About Menu Class

 

Menu class is mainly used for creating and managing menus.

 

Menu Class Methods

 

Menu.Add() adds a menu. The menu is initially empty. If the function succeeds, the return value is a MenuHandle. If the function fails, the return value is 0. Resources associated with a menu that is assigned to a window are freed automatically. If the menu is not assigned to a window, an application must free system resources associated with the menu before closing. An application frees menu resources by calling the Menu.Delete() function.

 

Menu.AddSubMenu( long MenuHandle, long Position, string Text ) adds a drop-down menu or submenu to the given menu. If the function succeeds, the return value is a MenuHandle. If the function fails, the return value is 0.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.
string Text: text of the submenu.

 

Menu.AddItem( long MenuHandle, long Position, long UncheckedBitmapHandle, long CheckedBitmapHandle, string Text ) adds a menu item to the specified drop-down menu, submenu, or shortcut menu. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.
long UncheckedBitmapHandle: the bitmap shown when the menu item is unchecked. If this parameter is 0 no bitmap is shown.
long CheckedBitmapHandle: the bitmap shown when the menu item is checked. If this parameter is 0 no bitmap is shown.
string Text: text of the submenu.

 

Menu.AddItemBitmap( long MenuHandle, long Position, long UncheckedBitmapHandle, long CheckedBitmapHandle, long BitmapHandle ) adds a menu item as a bitmap. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.
long UncheckedBitmapHandle: the bitmap shown when the menu item is unchecked. If this parameter is 0 no bitmap is shown.
long CheckedBitmapHandle: the bitmap shown when the menu item is checked. If this parameter is 0 no bitmap is shown.
long BitmapHandle: bitmap handle.

 

Menu.AddItemBarBreak( long MenuHandle, long Position ) functions the same as the Menu.AddItemBreak() a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is separated from the old column by a vertical line. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

Menu.AddItemBreak( long MenuHandle, long Position ) 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.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

Menu.AddItemSeparator( long MenuHandle, long Position ) draws a horizontal dividing line. This method is used only in a drop-down menu, submenu, or shortcut menu. If the fuction succeeds, the return value is the ItemIndex or -1 otherwise.

long MenuHandle: menu handle.
long Position: zero-based position of the new menu item. If this argument is -1, the new menu item is appended to the end of the menu.

 

Menu.SetItemEnabled( long MenuHandle, long ItemIndex, bool Enabled ) enables or disables a 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.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.
bool Enabled: enables (true) or disables (false) the menu item.

 

Menu.GetItemEnabled( long MenuHandle, long ItemIndex ) returns true if the menu item is enabled or false otherwise.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.SetItemChecked( long MenuHandle, long ItemIndex, bool 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.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.
bool Checked: selects (true) or clears (false) the check-mark attribute of the menu item.

 

Menu.GetItemChecked( long MenuHandle, long ItemIndex ) returns true if the specified menu item’s check-mark is checked or false otherwise.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.SetItemDefault( long MenuHandle, long ItemIndex ) Sets the default menu item for the specified menu.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.GetItemDefault( long MenuHandle ) returns the ItemIndex of the default menu item. If the function fails, the return value is -1.

long MenuHandle: menu handle.

 

Menu.SetItemRightOrder( long MenuHandle, long ItemIndex, bool 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. If the function succeeds, the return value is true. If the function fails, the return value is false.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.
bool RightOrder: sets (true) or removes (false) the right order.

 

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

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.SetItemBitmaps( long MenuHandle, long ItemIndex, long UncheckedBitmapHandle, long 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.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.
long UncheckedBitmapHandle: the bitmap shown when the menu item is unchecked. If this parameter is 0 no bitmap is shown.
long CheckedBitmapHandle: the bitmap shown when the menu item is checked. If this parameter is 0 no bitmap is shown.

 

Menu.SetItemClicked( long MenuHandle, long ItemIndex, bool Clicked ) sets the click state of a menu item.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.
bool Clicked: sets the menu item as clicked (true) or not (false).

 

Menu.GetItemClicked( long MenuHandle, long ItemIndex ) returns true if the user clicks on the given menu item or false otherwise.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.GetItemID( long MenuHandle, long ItemIndex ) returns the ItemID of a menu item (this is not an ItemIndex but an unique item identifier). If the menu ItemID is 0 or if the specified item opens a submenu, the return value is -1.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.GetItemCount( long 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.

long MenuHandle: menu handle.

 

Menu.DeleteItem( long MenuHandle, long ItemIndex ) Deletes an item from the specified menu. 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.

long MenuHandle: menu handle.
long ItemIndex: zero-based index of the menu item.

 

Menu.Delete( long MenuHandle ) Deletes a menu and frees any memory the menu occupied. If the function succeeds, the return value is true. If the function fails, the return value is false.

long MenuHandle: menu handle.

 

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

long WindowHandle: window handle.
long MenuHandle: menu handle.
long X: the horizontal location of the shortcut menu, in screen coordinates.
long Y: the vertical location of the shortcut menu, in screen coordinates.
long Flags: specifies 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 ItemID 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.

Use any reasonable combination of the following flags to modify the animation of a menu. For example, by selecting a horizontal and a vertical flag, you can achieve diagonal animation.

TPM_HORNEGANIMATION Animates the menu from right to left.

TPM_HORPOSANIMATION Animates the menu from left to right.

TPM_NOANIMATION Displays menu without animation.

TPM_VERNEGANIMATION Animates the menu from bottom to top.

TPM_VERPOSANIMATION Animates the menu from top to bottom.

TPM_RECURSE flag displays a menu when another menu is already displayed. This is intended to support context menus within a menu.

Use one of the following flags to specify whether to accommodate horizontal or vertical alignment.

TPM_HORIZONTAL If the menu cannot be shown at the specified location without overlapping the excluded rectangle, the system tries to accommodate the requested horizontal alignment before the requested vertical alignment.

TPM_VERTICAL If the menu cannot be shown at the specified location without overlapping the excluded rectangle, the system tries to accommodate the requested vertical alignment before the requested horizontal alignment.

TPM_LAYOUTRTL Use this flag for right-to-left text layout. By default, the text layout is left-to-right.

 

Code Example

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Giavapps.Windows.API;

public class CodeExample : MonoBehaviour
{

private long WindowHandle = 0;
private long MenuHandle = 0;
private long FileMenuHandle = 0;
private long EditMenuHandle = 0;
private long FileNewMenuItemIndex = 0;
private long FileOpenMenuItemIndex = 0;
private long FileExitMenuItemIndex = 0;
private long EditCutMenuItemIndex = 0;
private long EditCopyMenuItemIndex = 0;
private long EditPasteMenuItemIndex = 0;

void Start()
{
Plugin.Initialize();//Initializes Giavapps Windows API
WindowHandle = Window.Create(0, 100, 100, 400, 400, Constant.WS_VISIBLE | Constant.WS_SYSMENU | Constant.WS_MINIMIZEBOX | Constant.WS_MAXIMIZEBOX | Constant.WS_SIZEBOX, Constant.WS_EX_TOPMOST);//Creates a new window
Control.SetText(WindowHandle, "Giavapps Windows API");//Sets a new title for the specified window

MenuHandle = Menu.Add();//Adds a new menu

FileMenuHandle = Menu.AddSubMenu(MenuHandle, –1, "File");//Adds a new submenu
FileNewMenuItemIndex = Menu.AddItem(FileMenuHandle, –1, 0, 0, "New");//Adds a new menu item
FileOpenMenuItemIndex = Menu.AddItem(FileMenuHandle, –1, 0, 0, "Open");//Adds a new menu item
FileExitMenuItemIndex = Menu.AddItem(FileMenuHandle, –1, 0, 0, "Exit");//Adds a new menu item

EditMenuHandle = Menu.AddSubMenu(MenuHandle, –1, "Edit");//Adds a new submenu
EditNewMenuItemIndex = Menu.AddItem(EditMenuHandle, –1, 0, 0, "Cut");//Adds a new menu item
EditOpenMenuItemIndex = Menu.AddItem(EditMenuHandle, –1, 0, 0, "Copy");//Adds a new menu item
EditExitMenuItemIndex = Menu.AddItem(EditMenuHandle, –1, 0, 0, "Paste");//Adds a new menu item

Window.SetMenu(WindowHandle, MenuHandle);//Sets the previously added menu to the specified window
}

void Update()
{

//Checks if the specified window has been closed
if(Window.GetClosed(WindowHandle))
{
Control.Destroy(WindowHandle);//Destroys the specified window
}

//FILE > NEW
if(Menu.GetItemClicked(FileMenuHandle, FileNewMenuItemIndex))
{
Debug.Log("FILE > NEW");
}
//FILE > OPEN
else if(Menu.GetItemClicked(FileMenuHandle, FileOpenMenuItemIndex))
{
Debug.Log("FILE > OPEN");
}
//FILE > EXIT
else if(Menu.GetItemClicked(FileMenuHandle, FileExitMenuItemIndex))
{
Debug.Log("FILE > EXIT");
}
//EDIT > CUT
else if(Menu.GetItemClicked(EditMenuHandle, EditCutMenuItemIndex))
{
Debug.Log("EDIT > CUT");
}
//EDIT > COPY
else if(Menu.GetItemClicked(EditMenuHandle, EditCopyMenuItemIndex))
{
Debug.Log("EDIT > COPY");
}
//EDIT > PASTE
else if(Menu.GetItemClicked(EditMenuHandle, EditPasteMenuItemIndex))
{
Debug.Log("EDIT > PASTE");
}

}

void OnApplicationQuit()
{

Plugin.Deinitialize();//Deinitializes Giavapps Windows API
}

}

 

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.

Comments are closed.