Tree-View – Giavapps Windows API

 

 

api_treeview_create(ParentHandle, X, Y, W, H, Flags, ExFlags) This function creates a tree-view control.

ParentHandle: parent handle.
X: x coordinate.
Y: y coordinate.
W: width.
H: height.
Flags: Flags of the control. Flags must be separated with the symbol "|".
ExFlags: extended flags of the control. Flags must be separated with the symbol "|".

 

Flags

 

This control supports the Window Styles and you can specify any of the styles listed below:

 

TVS_CHECKBOXES Enables check boxes for items in a tree-view control. Once a tree-view control is created with this style, the style cannot be removed. Instead, you must destroy the control and create a new one in its place.

TVS_DISABLEDRAGDROP Prevents the tree-view control from sending TVN_BEGINDRAG notification messages.

TVS_EDITLABELS Allows the user to edit the labels of tree-view items.

TVS_FULLROWSELECT Enables full-row selection in the tree view. The entire row of the selected item is highlighted, and clicking anywhere on an item’s row causes it to be selected. This style cannot be used in conjunction with the TVS_HASLINES style.

TVS_HASBUTTONS Displays plus (+) and minus (-) buttons next to parent items. The user clicks the buttons to expand or collapse a parent item’s list of child items. To include buttons with items at the root of the tree view, TVS_LINESATROOT must also be specified.

TVS_HASLINES Uses lines to show the hierarchy of items.

TVS_INFOTIP Obtains ToolTip information.

TVS_LINESATROOT Uses lines to link items at the root of the tree-view control. This value is ignored if TVS_HASLINES is not also specified.

TVS_NOHSCROLL Disables horizontal scrolling in the control. The control will not display any horizontal scroll bars.

TVS_NONEVENHEIGHT Sets the height of the items. By default, the height of items must be an even value.

TVS_NOSCROLL Disables both horizontal and vertical scrolling in the control. The control will not display any scroll bars.

TVS_NOTOOLTIPS Disables ToolTips.

TVS_RTLREADING Causes text to be displayed from right-to-left (RTL). Usually, windows display text left-to-right (LTR). Windows can be mirrored to display languages such as Hebrew or Arabic that read RTL. Typically, tree-view text is displayed in the same direction as the text in its parent window. If TVS_RTLREADING is set, tree-view text reads in the opposite direction from the text in the parent window.

TVS_SHOWSELALWAYS Causes a selected item to remain selected when the tree-view control loses focus.

TVS_SINGLEEXPAND Causes the item being selected to expand and the item being unselected to collapse upon selection in the tree view. If the mouse is used to single-click the selected item and that item is closed, it will be expanded. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed.

TVS_TRACKSELECT Enables hot tracking in a tree-view control.

 

Extended Flags

 

This control supports the Extended Window Styles.

 

Return Value

 

If the function succeeds, the return value is a handle to the new tree-view control.

If the function fails, the return value is false.

To get extended error information, call api_control_get_last_error().

 

Control Functions

 

api_treeview_set_exstyle(TreeViewHandle, TreeViewExFlags) Sets extended styles to the given tree-view control.

TreeViewHandle: it must be a TreeViewHandle.
TreeViewExFlags: Value that indicates the extended style.

TreeViewExFlags argument can be a combination of the following flags:

TVS_EX_AUTOHSCROLL Remove the horizontal scroll bar and auto-scroll depending on mouse position.

TVS_EX_DIMMEDCHECKBOXES Include dimmed checkbox state if the control has the TVS_CHECKBOXES style.

TVS_EX_DOUBLEBUFFER Specifies how the background is erased or filled.

TVS_EX_DRAWIMAGEASYNC Retrieves calendar grid information.

TVS_EX_EXCLUSIONCHECKBOXES Include exclusion checkbox state if the control has the TVS_CHECKBOXES style.

TVS_EX_FADEINOUTEXPANDOS Fade expando buttons in or out when the mouse moves away or into a state of hovering over the control.

TVS_EX_MULTISELECT Not supported. Do not use.

TVS_EX_NOINDENTSTATE Do not indent the tree view for the expando buttons.

TVS_EX_NOSINGLECOLLAPSE Intended for internal use, not recommended for use in applications. Do not collapse the previously selected tree-view item unless it has the same parent as the new selection. This style must be used with the TVS_SINGLEEXPAND style.

TVS_EX_PARTIALCHECKBOXES Include partial checkbox state if the control has the TVS_CHECKBOXES style.

TVS_EX_RICHTOOLTIP Allow rich tooltips in the tree view (custom drawn with icon and text).

 

api_treeview_get_extstyle(TreeViewHandle) Returns the extended style for a tree-view control.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_add_item(TreeViewHandle, ParentItemHandle, InsertAfterItemHandle, HasChildren, ImageIndex, Text) Adds a new item in a tree-view control. The function returns the ItemHandle if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ParentItemHandle: Handle to the parent item. If this member is the TVI_ROOT value or false, the item is inserted at the root of the tree-view control.
InsertAfterItemHandle: Handle to the item after which the new item is to be inserted.
HasChildren: indicates whether the item has associated child items (true) or not (false).
ImageIndex: index in the tree-view control’s image list of the icon image to use when the item is in the nonselected state.
Text: text of the item.

The InsertAfterItemHandle argument can be a handle to the item after which the new item is to be inserted, or one of the following values:

TVI_FIRST Inserts the item at the beginning of the list.

TVI_LAST Inserts the item at the end of the list.

TVI_ROOT Add the item as a root item.

TVI_SORT Inserts the item into the list in alphabetical order.

 

api_treeview_set_item_text(TreeViewHandle, ItemHandle, Text) Sets the text of an item in a tree-view control. This function returns a true value if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_get_item_text(TreeViewHandle,ItemHandle) Returns the text of an item in a tree-view control. This function is limited to a maximum of 256 characters.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_set_item_image_index(TreeViewHandle,ItemHandle,UnselectedImageIndex,SelectedImageIndex) Sets the index in the tree-view control’s image list of the icon image to use when the item is selected or unselected.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.
UnselectedImageIndex: index in the tree-view control’s image list of the icon image to use when the item is in the nonselected state.
SelectedImageIndex: index in the tree-view control’s image list of the icon image to use when the item is in the selected state.

 

api_treeview_get_item_image_index(TreeViewHandle, ItemHandle, UnselectedOrSelectedImageIndex) Returns the index in the tree-view control’s image list of the icon image to use when the item is selected or unselected.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.
UnselectedOrSelectedImageIndex: returns the unselected (false) or selected (true) image index.

 

api_treeview_set_item_has_children(TreeViewHandle, ItemHandle, HasChildren) Sets child items to an item (The item shows (+) or (-) if has child items).

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.
HasChildren: indicates whether the item has associated child items (true) or not (false).

 

api_treeview_get_item_has_children(TreeViewHandle, ItemHandle) Returns true if the given item has child items or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_set_item_edit_label_start(TreeViewHandle, ItemHandle) Begins in-place editing of the specified item’s text, replacing the text of the item with a single-line edit control containing the text.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_set_item_edit_label_end(TreeViewHandle) Ends the editing of a tree-view item’s label.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_set_item_expanded(TreeViewHandle, ItemHandle, Expanded) Expands or collapses the list of child items associated with the specified parent item, if any.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.
Expanded: action flag.

Expanded argument can be one or more of the following values:

TVE_COLLAPSE Collapses the list.

TVE_COLLAPSERESET Collapses the list and removes the child items. The TVIS_EXPANDEDONCE state flag is reset. This flag must be used with the TVE_COLLAPSE flag.

TVE_EXPAND Expands the list.

TVE_EXPANDPARTIAL Partially expands the list. In this state the child items are visible and the parent item’s plus sign (+), indicating that it can be expanded, is displayed. This flag must be used in combination with the TVE_EXPAND flag.

TVE_TOGGLE Collapses the list if it is expanded or expands it if it is collapsed.

 

api_treeview_get_item_root(TreeViewHandle) Returns the topmost or very first item of the tree-view control if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_get_item_child(TreeViewHandle, ItemHandle) Returns the first child item of the specified tree-view item if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_get_item_parent(TreeViewHandle, ItemHandle) Returns the parent item of the specified tree-view item or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_get_item_count(TreeViewHandle) Returns a count of the items in a tree-view control.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_set_item_selection(TreeViewHandle, ItemHandle) Selects the specified tree-view item. This function returns a true value if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_get_item_selection(TreeViewHandle) Returns the handle to the item if successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_set_item_checked(TreeViewHandle, ItemHandle, Checked) Sets the item’s state image to checked or unchecked This function also sets the item’s checkbox to checked or unchecked in tree-view comtrols with TVS_CHECKBOXES style.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.
Checked: checks (true) or unchecks (false) the specified item.

 

api_treeview_get_item_checked(TreeViewHandle, ItemHandle) Returns true if the item’s state image is checked or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_delete_item(TreeViewHandle, ItemHandle) Removes an item and all its children from a tree-view control. This function returns true if the operation was successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ItemHandle: it must be an ItemHandle.

 

api_treeview_reset(TreeViewHandle) Deletes all items from a tree-view control. This function returns true if the operation was successful, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_set_tooltip(TreeViewHandle, TooltipHandle) Sets a tree-view control’s tooltip control. This function returns the handle to tooltip control previously set for the tree-view control, or false if tooltips were not previously used.

TreeViewHandle: it must be a TreeViewHandle.
TooltipHandle: it must be a TooltipHandle.

 

api_treeview_get_tooltip(TreeViewHandle) Returns the handle to the tooltip control, or false if the control is not using tooltips.

TreeViewHandle: it must be a TreeViewHandle.

 

api_treeview_set_imagelist(TreeViewHandle, ImageListHandle, ImageType) Sets the normal or state image list for a tree-view control and redraws the control using the new images. This function eturns the handle to the previous image list, if any, or false otherwise.

TreeViewHandle: it must be a TreeViewHandle.
ImageListHandle: it must be an ImageListHandle.
ImageType: Type of image list to set.

ImageType argument can be one of the following values:

TVSIL_NORMAL Indicates the normal image list, which contains selected, nonselected, and overlay images for the items of a tree-view control.

TVSIL_STATE Indicates the state image list. You can use state images to indicate application-defined item states. A state image is displayed to the left of an item’s selected or nonselected image.

 

api_treeview_get_imagelist(TreeViewHandle, ImageType) Returns the handle to the normal or state image list associated with a tree-view control.

TreeViewHandle: it must be a TreeViewHandle.
ImageType: Type of image list to set.

ImageType argument can be one of the following values:

TVSIL_NORMAL Indicates the normal image list, which contains selected, nonselected, and overlay images for the items of a tree-view control.

TVSIL_STATE Indicates the state image list. You can use state images to indicate application-defined item states. A state image is displayed to the left of an item’s selected or nonselected image.

 

Code Examples

 

Creating a Tree-View

 

treeview = api_treeview_create(window,10,10,160,160,WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES,WS_EX_CLIENTEDGE);

 

Adding Items

 

item1 = api_treeview_add_item(treeview,0,TVI_FIRST,1,-1,"Item 1");
subitem1 = api_treeview_add_item(treeview,item1,TVI_FIRST,0,-1,"Sub Item 1");
subitem2 = api_treeview_add_item(treeview,item1,subitem1,0,-1,"Sub Item 2");
subitem3 = api_treeview_add_item(treeview,item1,subitem2,0,-1,"Sub Item 3");
item2 = api_treeview_add_item(treeview,0,item1,0,-1,"Item 2");
item3 = api_treeview_add_item(treeview,0,item2,0,-1,"Item 3");

 

Deleting Items

 

api_treeview_delete_item(treeview,subitem2);

 

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 *

*