ListBox Class

 

 

About ListBox Class

 

ListBox class is mainly used for creating and managing list boxes.

 

ListBox Class Methods

 

ListBox.Create( long ParentHandle, long X, long Y, long Width, long Height, long Style, long ExStyle ) creates a list box. If the function succeeds, the return value is a handle to the new control. If the function fails, the return value is 0.

long ParentHandle: a handle to the parent or owner control of the control being created.
long X: x coordinate. You can also use CW_USEDEFAULT constant for this argument.
long Y: y coordinate. You can also use CW_USEDEFAULT constant for this argument.
long Width: width. You can also use CW_USEDEFAULT constant for this argument.
long Height: height. You can also use CW_USEDEFAULT constant for this argument.
long Style: the style of the control being created. This parameter can be a combination of the window styles and list box styles.
long ExStyle: the extended style of the control being created. This parameter can be a combination of the extended window styles.

 

ListBox.Exists( long ListBoxHandle ) returns true if the specified control was created with ListBox.Create() method and not destroyed yet or false otherwise. Note that all child controls are destroyed when parent control is destroyed. You can also call Control.Destroy() method for destroying a specific control with all of its children.

long ListBoxHandle: list box handle.

 

ListBox.Count() returns the total number of controls created with ListBox.Create() method and not destroyed yet. Note that all child controls are destroyed when parent control is destroyed. You can also call Control.Destroy() method for destroying a specific control with all of its children.

 

ListBox.GetHandleByIndex( ulong ListBoxIndex ) returns the handle from an index if the specified control was created with ListBox.Create() method and not destroyed yet or 0 otherwise. Note that all child controls are destroyed when parent control is destroyed. You can also call Control.Destroy() method for destroying a specific control with all of its children. ListBoxIndex parameter should be less or equal to ListBox.Count()-1.

ulong ListBoxIndex: zero-based index of the list box.

 

ListBox.AddItem( long ListBoxHandle, long ItemIndex, string ItemText ) adds a string or item data into a list box. The return value is the index of the position at which the string was inserted. If an error occurs, the return value is LB_ERR. If there is insufficient space to store the new string, the return value is LB_ERRSPACE.

long ListBoxHandle: list box handle.
long ItemIndex: zero-based index of the item or –1 to add it to the end of the list.
string ItemText: item text.

 

ListBox.GetItem( long ListBoxHandle, long ItemIndex ) returns a string from a list in a list box.

long ListBoxHandle: list box handle.
long ItemIndex: zero-based index of the item.

 

ListBox.GetItemCount( long ListBoxHandle ) returns the number of items in a list box.

long ListBoxHandle: list box handle.

 

ListBox.SetItemSelected( long ListBoxHandle, long ItemIndex ) sets the currently selected item in a list box. If an error occurs, the return value is LB_ERR. If the ItemIndex parameter is –1, the return value is LB_ERR even though no error occurred. Use this method only with single-selection list boxes. You cannot use it to set or remove a selection in a multiple-selection list box.

long ListBoxHandle: list box handle.
long ItemIndex: zero-based index of the item. If this parameter is -1, the list box is set to have no selection.

 

ListBox.GetItemSelected( long ListBoxHandle ) returns the index of the currently selected item, if any, in a single-selection list box. In a single-selection list box, the return value is the zero-based index of the currently selected item. If there is no selection, the return value is LB_ERR.

long ListBoxHandle: list box handle.

 

ListBox.GetItemMultiSelectedCount( long ListBoxHandle ) returns the total number of selected items in a multiple-selection list box. If the list box is a single-selection list box, the return value is LB_ERR.

long ListBoxHandle: list box handle.

 

ListBox.SetItemMultiSelected( long ListBoxHandle, long ItemIndex, bool Selected ) selects an item in a multiple-selection list box and, if necessary, scrolls the item into view. If an error occurs, the return value is LB_ERR.

long ListBoxHandle: list box handle.
long ItemIndex: zero-based index of the item. If this parameter is –1, the selection is added to or removed from all items, depending on the value of Selected, and no scrolling occurs.
long Selected: specifies how to set the selection. If this parameter is true, the item is selected and highlighted; if it is false, the highlight is removed and the item is no longer selected.

 

ListBox.GetItemMultiSelected( long ListBoxHandle ) Gets the selection state of an item. If an item is selected, the return value is greater than zero; otherwise, it is zero. If an error occurs, the return value is LB_ERR.

long ListBoxHandle: list box handle.

 

ListBox.DeleteItem( long ListBoxHandle, long ItemIndex ) Deletes the item at the specified location in a list in a list box. The return value is a count of the strings remaining in the list. The return value is LB_ERR if the wParam parameter specifies an index greater than the number of items in the list.

long ListBoxHandle: list box handle.
long ItemIndex: zero-based index of the item.

 

ListBox.Reset( long ListBoxHandle ) removes all items from the list box. Always returns LB_OKAY.

long ListBoxHandle: list box handle.

 

ListBox.SetItemSize( long ListBoxHandle, long Width, long Height ) sets the size of all items in a list box.

long ListBoxHandle: list box handle.
long Width: the width, in pixels, of all columns in a multiple-column list box.
long Height: the height, in pixels, of all items in a list box.

 

ListBox.GetItemWidth( long ListBoxHandle ) returns the width of all the items in a list box.

long ListBoxHandle: list box handle.

 

ListBox.GetItemHeight( long ListBoxHandle ) returns the height of all the items in a list box.

long ListBoxHandle: list box handle.

 

ListBox.SetSelectionChanged( long ListBoxHandle, bool Changed ) sets the current selection in the list box as changed.

long ListBoxHandle: list box handle.
bool Changed: sets the current selection in the list box as changed (true) or not (false).

 

ListBox.GetSelectionChanged( long ListBoxHandle ) returns true when the user changes the current selection in the list box or false otherwise. (This method only works on list boxes with LBS_NOTIFY style)

long ListBoxHandle: list box handle.

 

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 ListBoxHandle = 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
ListBoxHandle = ListBox.Create(WindowHandle, 10, 10, 150, 150, Constant.WS_VISIBLE | Constant.WS_CHILD | Constant.LBS_STANDARD, 0);//Creates a new list box
ListBox.AddItem(ListBoxHandle, –1, "Item "+ListBox.GetItemCount(ListBoxHandle));//Adds a new item to the list box
ListBox.AddItem(ListBoxHandle, –1, "Item "+ListBox.GetItemCount(ListBoxHandle));//Adds a new item to the list box
ListBox.AddItem(ListBoxHandle, –1, "Item "+ListBox.GetItemCount(ListBoxHandle)); //Adds a new item to the list box
}

void Update()
{

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

//Checks if the current selection in the list box has changed
if(ListBox.GetSelectionChanged(ListBoxHandle))
{
Debug.Log("LIST BOX SELECTION HAS CHANGED!");
}

}

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.