using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.PInvoke.User32;
namespace Vanara.PInvoke
{
public static partial class ComCtl32
{
///
public const int I_CHILDRENAUTO = -2;
///
public const int I_CHILDRENCALLBACK = -1;
/// TreeView's custom draw return meaning don't draw images. valid on CDRF_NOTIFYITEMPREPAINT
public const int TVCDRF_NOIMAGES = 0x00010000;
private const int TV_FIRST = 0x1100;
private const int TVN_FIRST = -400;
///
/// An application-defined callback function, which is called during a sort operation each time the relative order of two list items
/// needs to be compared.
///
/// Corresponds to the lParam member of the first TVITEM structure for the two items being compared.
/// Corresponds to the lParam member of the second TVITEM structure for the two items being compared.
/// Corresponds to the lParam member of this structure.
///
/// The callback function must return a negative value if the first item should precede the second, a positive value if the first
/// item should follow the second, or zero if the two items are equivalent.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773462")]
public delegate int PFNTVCOMPARE(IntPtr lParam1, IntPtr lParam2, IntPtr lParamSort);
/// Action that the sender (the tree-view control) should execute on return.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773413")]
public enum AsyncDrawRetFlags
{
///
/// Proceed to draw the image anyway, that is, synchronously extract the image and paint. Assuming the control is on the UI
/// thread, use of this flag implies low priority UI performance, since extraction times may vary and the UI could be
/// unresponsive for an extended period of time during extraction.
///
ADRF_DRAWSYNC = 0,
/// Do not draw an image.
ADRF_DRAWNOTHING = 1,
/// Draw fallback text.
ADRF_DRAWFALLBACK = 2,
/// Draw the image specified by iRetImageIndex.
ADRF_DRAWIMAGE = 3,
}
/// Specifies the item to retrieve using TVM_GETNEXTITEM or the action for TVM_SELECTITEM.
[PInvokeData("Commctrl.h", MSDNShortId = "bb760143")]
public enum TreeViewActionFlag
{
/// Retrieves the currently selected item. You can use the TreeView_GetSelection macro to send this message.
TVGN_CARET = 0x0009,
///
/// Retrieves the first child item of the item specified by the hitem parameter. You can use the TreeView_GetChild macro to send
/// this message.
///
TVGN_CHILD = 0x0004,
///
/// Retrieves the item that is the target of a drag-and-drop operation. You can use the TreeView_GetDropHilight macro to send
/// this message.
///
TVGN_DROPHILITE = 0x0008,
///
/// Retrieves the first item that is visible in the tree-view window. You can use the TreeView_GetFirstVisible macro to send this message.
///
TVGN_FIRSTVISIBLE = 0x0005,
///
/// Version 4.71. Retrieves the last expanded item in the tree. This does not retrieve the last item visible in the tree-view
/// window. You can use the TreeView_GetLastVisible macro to send this message.
///
TVGN_LASTVISIBLE = 0x000A,
/// Retrieves the next sibling item. You can use the TreeView_GetNextSibling macro to send this message.
TVGN_NEXT = 0x0001,
///
/// Windows Vista and later. Retrieves the next selected item. You can use the TreeView_GetNextSelected macro to send this message.
///
TVGN_NEXTSELECTED = 0x000B,
///
/// Retrieves the next visible item that follows the specified item. The specified item must be visible. Use the TVM_GETITEMRECT
/// message to determine whether an item is visible. You can use the TreeView_GetNextVisible macro to send this message.
///
TVGN_NEXTVISIBLE = 0x0006,
/// Retrieves the parent of the specified item. You can use the TreeView_GetParent macro to send this message.
TVGN_PARENT = 0x0003,
/// Retrieves the previous sibling item. You can use the TreeView_GetPrevSibling macro to send this message.
TVGN_PREVIOUS = 0x0002,
///
/// Retrieves the first visible item that precedes the specified item. The specified item must be visible. Use the
/// TVM_GETITEMRECT message to determine whether an item is visible. You can use the TreeView_GetPrevVisible macro to send this message.
///
TVGN_PREVIOUSVISIBLE = 0x0007,
///
/// Retrieves the topmost or very first item of the tree-view control. You can use the TreeView_GetRoot macro to send this message.
///
TVGN_ROOT = 0x0000,
///
/// When a single item is selected, ensures that the treeview does not expand the children of that item. This is valid only if
/// used with the TVGN_CARET flag.
///
TVSI_NOSINGLEEXPAND = 0x8000
}
/// Action to take when using TVM_EXPAND.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773568")]
[Flags]
public enum TreeViewExpandFlags
{
/// Collapses the list.
TVE_COLLAPSE = 0x0001,
/// Expands the list.
TVE_EXPAND = 0x0002,
/// Collapses the list if it is expanded or expands it if it is collapsed.
TVE_TOGGLE = 0x0003,
///
/// Version 4.70. 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_EXPANDPARTIAL = 0x4000,
///
/// 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_COLLAPSERESET = 0x8000,
}
/// Information about the results of a hit test.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773448")]
[Flags]
public enum TreeViewHitTestFlags
{
/// In the client area, but below the last item.
TVHT_NOWHERE = 0x0001,
/// On the bitmap associated with an item.
TVHT_ONITEMICON = 0x0002,
/// On the label (string) associated with an item.
TVHT_ONITEMLABEL = 0x0004,
/// On the bitmap or label associated with an item.
TVHT_ONITEM = TVHT_ONITEMICON | TVHT_ONITEMLABEL | TVHT_ONITEMSTATEICON,
/// In the indentation associated with an item.
TVHT_ONITEMINDENT = 0x0008,
/// On the button associated with an item.
TVHT_ONITEMBUTTON = 0x0010,
/// In the area to the right of an item.
TVHT_ONITEMRIGHT = 0x0020,
/// On the state icon for a tree-view item that is in a user-defined state.
TVHT_ONITEMSTATEICON = 0x0040,
/// Above the client area.
TVHT_ABOVE = 0x0100,
/// Below the client area.
TVHT_BELOW = 0x0200,
/// To the right of the client area.
TVHT_TORIGHT = 0x0400,
/// To the left of the client area.
TVHT_TOLEFT = 0x0800,
}
/// Values used as alternatives to tree item handle (HTREEITEM) in TVINSERTSTRUCT.hInsertAfter.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773448")]
public enum TreeViewInsert
{
/// Inserts the item at the beginning of the list.
TVI_FIRST = -0x0FFFF,
/// Inserts the item at the end of the list.
TVI_LAST = -0x0FFFE,
/// Add the item as a root item.
TVI_ROOT = -0x10000,
/// Inserts the item into the list in alphabetical order.
TVI_SORT = -0x0FFFD
}
///
/// Used in and mask members to indicate which structure members contain valid data.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773459")]
[Flags]
public enum TreeViewItemMask
{
/// The cChildren member is valid.
TVIF_CHILDREN = 0x0040,
///
/// The tree-view control will retain the supplied information and will not request it again. This flag is valid only when
/// processing the TVN_GETDISPINFO notification.
///
TVIF_DI_SETITEM = 0x1000,
/// Version 6.00 and Windows Vista. The iExpandedImage member is valid.
TVIF_EXPANDEDIMAGE = 0x0200,
/// The hItem member is valid.
TVIF_HANDLE = 0x0010,
/// The iImage member is valid.
TVIF_IMAGE = 0x0002,
/// The iIntegral member is valid.
TVIF_INTEGRAL = 0x0080,
/// The lParam member is valid.
TVIF_PARAM = 0x0004,
/// The iSelectedImage member is valid.
TVIF_SELECTEDIMAGE = 0x0020,
/// The state and stateMask members are valid.
TVIF_STATE = 0x0008,
/// Version 6.00 and Windows Vista. The uStateEx member is valid.
TVIF_STATEEX = 0x0100,
/// The pszText and cchTextMax members are valid.
TVIF_TEXT = 0x0001,
}
///
/// Set of bit flags and image list indexes that indicate the item's state. When setting the state of an item, the stateMask member
/// indicates the valid bits of this member. When retrieving the state of an item, this member returns the current state for the bits
/// indicated in the stateMask member.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773459")]
[Flags]
public enum TreeViewItemStates
{
///
/// The item is selected. Its appearance depends on whether it has the focus. The item will be drawn using the system colors for selection.
///
TVIS_SELECTED = 0x0002,
/// The item is selected as part of a cut-and-paste operation.
TVIS_CUT = 0x0004,
/// The item is selected as a drag-and-drop target.
TVIS_DROPHILITED = 0x0008,
/// The item is bold.
TVIS_BOLD = 0x0010,
///
/// The item's list of child items is currently expanded; that is, the child items are visible. This value applies only to parent items.
///
TVIS_EXPANDED = 0x0020,
///
/// The item's list of child items has been expanded at least once. The TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification codes
/// are not generated for parent items that have this state set in response to a TVM_EXPAND message. Using TVE_COLLAPSE and
/// TVE_COLLAPSERESET with TVM_EXPAND will cause this state to be reset. This value applies only to parent items.
///
TVIS_EXPANDEDONCE = 0x0040,
///
/// Version 4.70. A partially expanded tree-view item. In this state, some, but not all, of the child items are visible and the
/// parent item's plus symbol is displayed.
///
TVIS_EXPANDPARTIAL = 0x0080,
/// Mask for the bits used to specify the item's overlay image index.
TVIS_OVERLAYMASK = 0x0F00,
/// Mask for the bits used to specify the item's state image index.
TVIS_STATEIMAGEMASK = 0xF000,
/// Same as TVIS_STATEIMAGEMASK.
TVIS_USERMASK = 0xF000,
/// Version 6.00 and Windows Vista. The iExpandedImage member is valid.
TVIF_EXPANDEDIMAGE = 0x0200,
/// Version 6.00 and Windows Vista. The uStateEx member is valid.
TVIF_STATEEX = 0x0100
}
/// Tree view item extended states.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773459")]
[Flags]
public enum TreeViewItemStatesEx
{
///
/// Creates a flat item—the item is virtual and is not visible in the tree; instead, its children take its place in the tree
/// hierarchy. This state is valid only when adding an item to the tree-view control.
///
TVIS_EX_FLAT = 0x0001,
/// Windows Vista and later. Creates a control that is drawn in gray, that the user cannot interact with.
TVIS_EX_DISABLED = 0x0002,
/// Creates a separate HWND for the item. This state is valid only when adding an item to the tree-view control.
TVIS_EX_HWND = 0x0004,
}
///
/// Tree View Messages
///
[PInvokeData("Commctrl.h", MSDNShortId = "ff486106")]
public enum TreeViewMessage
{
///
/// Removes an item and all its children from a tree-view control. You can send this message explicitly or by using the
/// TreeView_DeleteItem macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// HTREEITEM handle to the item to delete. If lParam is set to TVI_ROOT or to NULL, all items are deleted. You can
/// also use the TreeView_DeleteAllItems macro to delete all items.
///
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// It is not safe to delete items in response to a notification such as TVN_SELCHANGING.
/// Once an item is deleted, its handle is invalid and cannot be used.
/// The parent window receives a TVN_DELETEITEM notification code when each item is removed.
///
/// If the item label is being edited, the edit operation is canceled and the parent window receives the TVN_ENDLABELEDIT
/// notification code.
///
///
/// If you delete all items in a tree-view control that has the TVS_NOSCROLL style, items subsequently added may not
/// display properly. For more information, see TreeView_DeleteAllItems.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-deleteitem
TVM_DELETEITEM = TV_FIRST + 1,
///
/// The TVM_EXPAND message expands or collapses the list of child items associated with the specified parent item, if any.
/// You can send this message explicitly or by using the TreeView_Expand macro.
/// Parameters
/// wParam
/// Action flag. This parameter can be one or more of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// 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
///
/// Version 4.70. 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.
///
///
/// lParam
/// Handle to the parent item to expand or collapse.
/// Returns
/// Returns nonzero if the operation was successful, or zero otherwise.
///
///
///
/// Expanding a node that is already expanded is considered a successful operation and SendMessage returns a nonzero
/// value. Collapsing a node returns zero if the node is already collapsed; otherwise it returns nonzero. Attempting to expand or
/// collapse a node that has no children is considered a failure and SendMessage returns zero.
///
///
/// When an item is first expanded by a TVM_EXPAND message, the action generates TVN_ITEMEXPANDING and TVN_ITEMEXPANDED
/// notification codes and the item's TVIS_EXPANDEDONCE state flag is set. As long as this state flag remains set,
/// subsequent TVM_EXPAND messages do not generate TVN_ITEMEXPANDING or TVN_ITEMEXPANDED notifications. To reset the
/// TVIS_EXPANDEDONCE state flag, you must send a TVM_EXPAND message with the TVE_COLLAPSE and TVE_COLLAPSERESET
/// flags set. Attempting to explicitly set TVIS_EXPANDEDONCE will result in unpredictable behavior.
///
///
/// The expand operation may fail if the owner of the treeview control denies the operation in response to a TVN_ITEMEXPANDING notification.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-expand
TVM_EXPAND = TV_FIRST + 2,
///
/// Retrieves the bounding rectangle for a tree-view item and indicates whether the item is visible. You can send this message
/// explicitly or by using the TreeView_GetItemRect macro.
/// Parameters
/// wParam
///
/// Value specifying the portion of the item for which to retrieve the bounding rectangle. If this parameter is TRUE, the
/// bounding rectangle includes only the text of the item. Otherwise, it includes the entire line that the item occupies in the
/// tree-view control.
///
/// lParam
///
/// Pointer to a RECT structure that, when sending the message, contains the handle of the item to retrieve the rectangle
/// for. See the example below for more information on how to place the item handle in this parameter. After returning from the
/// message, this parameter contains the bounding rectangle. The coordinates are relative to the upper-left corner of the
/// tree-view control.
///
/// Returns
///
/// If the item is visible and the bounding rectangle was successfully retrieved, the return value is TRUE. Otherwise, the
/// message returns FALSE and does not retrieve the bounding rectangle.
///
///
///
///
/// When sending this message, the lParam parameter contains the handle of the item that the rectangle is being retrieved for.
/// The handle is placed in lParam as shown in the following example:
///
///
/// RECT rc; *(HTREEITEM*)&rc = hTreeItem; SendMessage(hwndTreeView, TVM_GETITEMRECT, FALSE, (LPARAM)&rc);
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getitemrect
TVM_GETITEMRECT = TV_FIRST + 4,
///
/// Retrieves a count of the items in a tree-view control. You can send this message explicitly or by using the
/// TreeView_GetCount macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the count of items.
///
///
/// The node count returned by TreeView_GetCount is limited to integer values. If you add a node beyond 32767 the macro
/// returns a negative value. After adding 65536 nodes the count returns to zero. When this occurs, the tree-view control appears
/// empty with no scrollbars.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getcount
TVM_GETCOUNT = TV_FIRST + 5,
///
/// Retrieves the amount, in pixels, that child items are indented relative to their parent items. You can send this message
/// explicitly or by using the TreeView_GetIndent macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the amount of indentation.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getindent
TVM_GETINDENT = TV_FIRST + 6,
///
/// Sets the width of indentation for a tree-view control and redraws the control to reflect the new width. You can send this
/// message explicitly or by using the TreeView_SetIndent macro.
/// Parameters
/// wParam
///
/// Width, in pixels, of the indentation. If this parameter is less than the system-defined minimum width, the new width is set
/// to the system-defined minimum.
///
/// lParam
/// Must be zero.
/// Returns
/// No return value.
///
///
/// The system-defined minimum indent value is typically five pixels, but it is not fixed. To retrieve the exact value of the
/// minimum indent on a particular system, send a TVM_SETINDENT message with wParam set to zero. Then send a
/// TVM_GETINDENT message to retrieve the minimum indent value.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setindent
TVM_SETINDENT = TV_FIRST + 7,
///
/// Retrieves the handle to the normal or state image list associated with a tree-view control. You can send this message
/// explicitly or by using the TreeView_GetImageList macro.
/// Parameters
/// wParam
/// Type of image list to retrieve. This parameter can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// 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.
///
///
///
/// lParam
/// Must be zero.
/// Returns
/// Returns an HIMAGELIST handle to the specified image list.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getimagelist
TVM_GETIMAGELIST = TV_FIRST + 8,
///
/// Sets the normal or state image list for a tree-view control and redraws the control using the new images. You can send this
/// message explicitly or by using the TreeView_SetImageList macro.
/// Parameters
/// wParam
/// Type of image list to set. This parameter can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// 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.
///
///
///
/// lParam
///
/// Handle to the image list. If lParam is NULL, the message removes the specified image list from the tree-view control.
///
/// Returns
/// Returns the handle to the previous image list, if any, or NULL otherwise.
///
///
/// The tree-view control will not destroy the image list specified with this message. Your application must destroy the image
/// list when it is no longer needed.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setimagelist
TVM_SETIMAGELIST = TV_FIRST + 9,
///
/// Retrieves the tree-view item that bears the specified relationship to a specified item. You can send this message explicitly,
/// by using the TreeView_GetNextItem macro.
/// Parameters
/// wParam
/// Flag specifying the item to retrieve. This parameter can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// TVGN_CARET
/// Retrieves the currently selected item. You can use the TreeView_GetSelection macro to send this message.
///
/// -
/// TVGN_CHILD
///
/// Retrieves the first child item of the item specified by the hitem parameter. You can use the TreeView_GetChild
/// macro to send this message.
///
///
/// -
/// TVGN_DROPHILITE
///
/// Retrieves the item that is the target of a drag-and-drop operation. You can use the TreeView_GetDropHilight macro to
/// send this message.
///
///
/// -
/// TVGN_FIRSTVISIBLE
///
/// Retrieves the first item that is visible in the tree-view window. You can use the TreeView_GetFirstVisible macro to
/// send this message.
///
///
/// -
/// TVGN_LASTVISIBLE
///
/// Version 4.71. Retrieves the last expanded item in the tree. This does not retrieve the last item visible in the tree-view
/// window. You can use the TreeView_GetLastVisible macro to send this message.
///
///
/// -
/// TVGN_NEXT
/// Retrieves the next sibling item. You can use the TreeView_GetNextSibling macro to send this message.
///
/// -
/// TVGN_NEXTSELECTED
///
/// Windows Vista and later. Retrieves the next selected item. You can use the TreeView_GetNextSelected macro to
/// send this message.
///
///
/// -
/// TVGN_NEXTVISIBLE
///
/// Retrieves the next visible item that follows the specified item. The specified item must be visible. Use the
/// TVM_GETITEMRECT message to determine whether an item is visible. You can use the TreeView_GetNextVisible macro
/// to send this message.
///
///
/// -
/// TVGN_PARENT
/// Retrieves the parent of the specified item. You can use the TreeView_GetParent macro to send this message.
///
/// -
/// TVGN_PREVIOUS
/// Retrieves the previous sibling item. You can use the TreeView_GetPrevSibling macro to send this message.
///
/// -
/// TVGN_PREVIOUSVISIBLE
///
/// Retrieves the first visible item that precedes the specified item. The specified item must be visible. Use the
/// TVM_GETITEMRECT message to determine whether an item is visible. You can use the TreeView_GetPrevVisible macro
/// to send this message.
///
///
/// -
/// TVGN_ROOT
///
/// Retrieves the topmost or very first item of the tree-view control. You can use the TreeView_GetRoot macro to send this message.
///
///
///
/// lParam
/// Handle to an item.
/// Returns
///
/// Returns the handle to the item if successful. For most cases, the message returns a NULL value to indicate an error.
/// See the Remarks section for details.
///
///
///
///
/// This message will return NULL if the item being retrieved is the root node of the tree. For example, if you use this
/// message with the TVGN_PARENT flag on a first-level child of the tree view's root node, the message will return NULL.
///
/// You can also use one of these related macros:
///
///
///
///
/// -
/// TreeView_GetChild
///
/// -
/// TreeView_GetDropHilight
///
/// -
/// TreeView_GetFirstVisible
///
/// -
/// TreeView_GetLastVisible
///
/// -
/// TreeView_GetNextSibling
///
/// -
/// TreeView_GetNextVisible
///
/// -
/// TreeView_GetParent
///
/// -
/// TreeView_GetPrevSibling
///
/// -
/// TreeView_GetPrevVisible
///
/// -
/// TreeView_GetRoot
///
/// -
/// TreeView_GetSelection
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getnextitem
TVM_GETNEXTITEM = TV_FIRST + 10,
///
/// Selects the specified tree-view item, scrolls the item into view, or redraws the item in the style used to indicate the
/// target of a drag-and-drop operation. You can send this message explicitly or by using the TreeView_Select,
/// TreeView_SelectItem, or TreeView_SelectDropTarget macro.
/// Parameters
/// wParam
/// Action flag. This parameter can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// TVGN_CARET
///
/// Sets the selection to the specified item. The tree-view control's parent window receives the TVN_SELCHANGING and
/// TVN_SELCHANGED notification codes.
///
///
/// -
/// TVGN_DROPHILITE
/// Redraws the specified item in the style used to indicate the target of a drag-and-drop operation.
///
/// -
/// TVGN_FIRSTVISIBLE
///
/// Ensures that the specified item is visible, and, if possible, displays it at the top of the control's window. Tree-view
/// controls display as many items as will fit in the window. If the specified item is near the bottom of the control's hierarchy
/// of items, it might not become the first visible item, depending on how many items fit in the window.
///
///
/// -
/// TVSI_NOSINGLEEXPAND
///
/// When a single item is selected, ensures that the treeview does not expand the children of that item. This is valid only if
/// used with the TVGN_CARET flag.
///
///
///
/// lParam
/// Handle to an item. If lParam is NULL, the control is set to have no selected item.
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// If the specified item is the child of a collapsed parent item, the parent's list of child items is expanded to reveal the
/// specified item. In this case, the control's parent window receives the TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification codes.
///
///
/// Using the TreeView_SelectItem macro is equivalent to sending the TVM_SELECTITEM message with wParam set to the
/// TVGN_CARET value. Using the TreeView_SelectDropTarget macro is equivalent to sending the TVM_SELECTITEM message
/// with wParam set to the TVGN_DROPHILITE value. Using TreeView_SelectSetFirstVisible is equivalent to sending the
/// TVM_SELECTITEM message with wParam set to the TVGN_FIRSTVISIBLE value.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-selectitem
TVM_SELECTITEM = TV_FIRST + 11,
///
/// Retrieves the handle to the edit control being used to edit a tree-view item's text. You can send this message explicitly or
/// by using the TreeView_GetEditControl macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the handle to the edit control if successful, or NULL otherwise.
///
///
///
/// When label editing begins, an edit control is created, but not positioned or displayed. Before it is displayed, the tree-view
/// control sends its parent window an TVN_BEGINLABELEDIT notification code.
///
///
/// To customize label editing, implement a handler for TVN_BEGINLABELEDIT and have it send a TVM_GETEDITCONTROL message
/// to the tree-view control. If a label is being edited, the return value will be a handle to the edit control. Use this handle
/// to customize the edit control by sending the usual EM_XXX messages.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-geteditcontrol
TVM_GETEDITCONTROL = TV_FIRST + 15,
///
/// Obtains the number of items that can be fully visible in the client window of a tree-view control. You can send this message
/// explicitly or by using the TreeView_GetVisibleCount macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the number of items that can be fully visible in the client window of the tree-view control.
///
///
///
/// The number of items that can be fully visible may be greater than the number of items in the control. The control calculates
/// this value by dividing the height of the client window by the height of an item.
///
///
/// Note that the return value is the number of items that can be fully visible. If you can see all of 20 items and part of one
/// more item, the return value is 20.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getvisiblecount
TVM_GETVISIBLECOUNT = TV_FIRST + 16,
///
/// Determines the location of the specified point relative to the client area of a tree-view control. You can send this message
/// explicitly or by using the TreeView_HitTest macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// Pointer to a TVHITTESTINFO structure. When the message is sent, the pt member specifies the coordinates of the
/// point to test. When the message returns, the hItem member is the handle to the item at the specified point or
/// NULL if no item occupies the point. Also, when the message returns, the flags member is a hit test value that
/// indicates the location of the specified point. For a list of hit test values, see the description of the TVHITTESTINFO structure.
///
/// Returns
///
/// Returns the handle to the tree-view item that occupies the specified point, or NULL if no item occupies the point.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-hittest
TVM_HITTEST = TV_FIRST + 17,
///
/// Creates a dragging bitmap for the specified item in a tree-view control. The message also creates an image list for the
/// bitmap and adds the bitmap to the image list. An application can display the image when dragging the item by using the image
/// list functions. You can send this message explicitly or by using the TreeView_CreateDragImage macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Handle to the item that receives the new dragging bitmap.
/// Returns
/// Returns the handle to the image list to which the dragging bitmap was added if successful, or NULL otherwise.
///
///
///
/// If you create a tree-view control without an associated image list, you cannot use the TVM_CREATEDRAGIMAGE message to
/// create the image to display during a drag operation. You must implement your own method of creating a drag cursor.
///
/// Your application is responsible for destroying the image list when it is no longer needed.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-createdragimage
TVM_CREATEDRAGIMAGE = TV_FIRST + 18,
///
/// Sorts the child items of the specified parent item in a tree-view control. You can send this message explicitly or by using
/// the TreeView_SortChildren macro.
/// Parameters
/// wParam
///
/// Value that specifies whether the sorting is recursive. Set wParam to TRUE to sort all levels of child items below the
/// parent item. Otherwise, only the parent's immediate children are sorted.
///
/// lParam
/// Handle to the parent item whose child items are to be sorted.
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// This message alphabetizes the tree items using lstrcmpi on the item name. You can use the TVM_SORTCHILDRENCB
/// message to customize the ordering behavior.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-sortchildren
TVM_SORTCHILDREN = TV_FIRST + 19,
///
/// Ensures that a tree-view item is visible, expanding the parent item or scrolling the tree-view control, if necessary. You can
/// send this message explicitly or by using the TreeView_EnsureVisible macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Handle to the item.
/// Returns
///
/// Returns nonzero if the system scrolled the items in the tree-view control and no items were expanded. Otherwise, the message
/// returns zero.
///
///
///
/// If the TVM_ENSUREVISIBLE message expands the parent item, the parent window receives the TVN_ITEMEXPANDING and
/// TVN_ITEMEXPANDED notification codes.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-ensurevisible
TVM_ENSUREVISIBLE = TV_FIRST + 20,
///
/// Sorts tree-view items using an application-defined callback function that compares the items. You can send this message
/// explicitly or by using the TreeView_SortChildrenCB macro.
/// Parameters
/// wParam
/// Reserved. Must be zero.
/// lParam
///
/// Pointer to a TVSORTCB structure. The lpfnCompare member is the address of the application-defined callback
/// function, which is called during the sort operation each time the relative order of two list items needs to be compared. For
/// more information about the callback function, see the description of TVSORTCB.
///
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-sortchildrencb
TVM_SORTCHILDRENCB = TV_FIRST + 21,
///
/// Ends the editing of a tree-view item's label. You can send this message explicitly or by using the
/// TreeView_EndEditLabelNow macro.
/// Parameters
/// wParam
///
/// Variable that indicates whether the editing is canceled without being saved to the label. If this parameter is TRUE,
/// the system cancels editing without saving the changes. Otherwise, the system saves the changes to the label.
///
/// lParam
/// Must be zero.
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
/// This message causes the TVN_ENDLABELEDIT notification code to be sent to the parent window of the tree-view control.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-endeditlabelnow
TVM_ENDEDITLABELNOW = TV_FIRST + 22,
///
/// Sets a tree-view control's child tooltip control. You can send this message explicitly or by using the
/// TreeView_SetToolTips macro.
/// Parameters
/// wParam
/// Handle to a tooltip control.
/// lParam
/// Must be zero.
/// Returns
///
/// Returns the handle to tooltip control previously set for the tree-view control, or NULL if tooltips were not
/// previously used.
///
///
///
/// When created, tree-view controls automatically create a child tooltip control. To prevent a tree-view control from using
/// tooltips, create the control with the TVS_NOTOOLTIPS style.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-settooltips
TVM_SETTOOLTIPS = TV_FIRST + 24,
///
/// Retrieves the handle to the child tooltip control used by a tree-view control. You can send this message explicitly or by
/// using the TreeView_GetToolTips macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the handle to the child tooltip control, or NULL if the control is not using tooltips.
///
///
/// When created, tree-view controls automatically create a child tooltip control. To cause a tree-view control not to use
/// tooltips, create the control with the TVS_NOTOOLTIPS style.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-gettooltips
TVM_GETTOOLTIPS = TV_FIRST + 25,
///
/// Sets the insertion mark in a tree-view control. You can send this message explicitly or by using the
/// TreeView_SetInsertMark macro.
/// Parameters
/// wParam
///
/// BOOL value that specifies if the insertion mark is placed before or after the specified item. If this argument is
/// nonzero, the insertion mark will be placed after the item. If this argument is zero, the insertion mark will be placed before
/// the item.
///
/// lParam
///
/// HTREEITEM that specifies at which item the insertion mark will be placed. If this argument is NULL, the
/// insertion mark is removed.
///
/// Returns
/// Returns nonzero if successful, or zero otherwise.
///
///
/// In some circumstances, the insert mark can appear in two places after a node is expanded. If you are using insertion marks,
/// it is recommended that you force a refresh of the control after expanding a node.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setinsertmark
TVM_SETINSERTMARK = TV_FIRST + 26,
///
/// Sets the Unicode character format flag for the control. This message allows you to change the character set used by the
/// control at run time rather than having to re-create the control. You can send this message explicitly or use the
/// TreeView_SetUnicodeFormat macro.
/// Parameters
/// wParam
///
/// Determines the character set that is used by the control. If this value is nonzero, the control will use Unicode characters.
/// If this value is zero, the control will use ANSI characters.
///
/// lParam
/// Must be zero.
/// Returns
/// Returns the previous Unicode format flag for the control.
///
/// See the remarks for CCM_SETUNICODEFORMAT for a discussion of this message.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setunicodeformat
TVM_SETUNICODEFORMAT = CommonControlMessage.CCM_SETUNICODEFORMAT,
///
/// Retrieves the Unicode character format flag for the control. You can send this message explicitly or use the
/// TreeView_GetUnicodeFormat macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
///
/// Returns the Unicode format flag for the control. If this value is nonzero, the control is using Unicode characters. If this
/// value is zero, the control is using ANSI characters.
///
///
/// See the remarks for CCM_GETUNICODEFORMAT for a discussion of this message.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getunicodeformat
TVM_GETUNICODEFORMAT = CommonControlMessage.CCM_GETUNICODEFORMAT,
///
/// Sets the height of the tree-view items. You can send this message explicitly or by using the TreeView_SetItemHeight macro.
/// Parameters
/// wParam
///
/// New height of every item in the tree view, in pixels. Heights less than 1 will be set to 1. If this argument is not even and
/// the tree-view control does not have the TVS_NONEVENHEIGHT style, this value will be rounded down to the nearest even
/// value. If this argument is -1, the control will revert to using its default item height.
///
/// lParam
/// Must be zero.
/// Returns
/// Returns the previous height of the items, in pixels.
///
///
/// The tree-view control uses this value for the height of all items. To modify the height of individual items, see the
/// description of the iIntegral member of the TVITEMEX structure.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setitemheight
TVM_SETITEMHEIGHT = TV_FIRST + 27,
///
/// Retrieves the current height of the each tree-view item. You can send this message explicitly or by using the
/// TreeView_GetItemHeight macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the height of each item, in pixels.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getitemheight
TVM_GETITEMHEIGHT = TV_FIRST + 28,
///
/// Sets the background color of the control. You can send this message explicitly or by using the TreeView_SetBkColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// COLORREF value that contains the new background color. If this value is -1, the control will revert to using the
/// system color for the background color.
///
/// Returns
///
/// Returns a COLORREF value that represents the previous background color. If this value is -1, the control was using the
/// system color for the background color.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setbkcolor
TVM_SETBKCOLOR = TV_FIRST + 29,
///
/// Sets the text color of the control. You can send this message explicitly or by using the TreeView_SetTextColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// COLORREF value that contains the new text color. If this argument is -1, the control will revert to using the system
/// color for the text color.
///
/// Returns
///
/// Returns a COLORREF value that represents the previous text color. If this value is -1, the control was using the
/// system color for the text color.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-settextcolor
TVM_SETTEXTCOLOR = TV_FIRST + 30,
///
/// Retrieves the current background color of the control. You can send this message explicitly or by using the
/// TreeView_GetBkColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
///
/// Returns a COLORREF value that represents the current background color. If this value is -1, the control is using the
/// system color for the background color.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getbkcolor
TVM_GETBKCOLOR = TV_FIRST + 31,
///
/// Retrieves the current text color of the control. You can send this message explicitly or by using the
/// TreeView_GetTextColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
///
/// Returns a COLORREF value that represents the current text color. If this value is -1, the control is using the system
/// color for the text color.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-gettextcolor
TVM_GETTEXTCOLOR = TV_FIRST + 32,
///
/// Sets the maximum scroll time for the tree-view control. You can send this message explicitly or by using the
/// TreeView_SetScrollTime macro.
/// Parameters
/// wParam
/// New maximum scroll time, in milliseconds.
/// lParam
/// Must be zero.
/// Returns
/// Returns the previous maximum scroll time, in milliseconds.
///
///
/// The maximum scroll time is the longest amount of time that a scroll operation can take. Scrolling will be adjusted so that
/// the scroll will take place within the maximum scroll time. A scroll operation may take less time than the maximum.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setscrolltime
TVM_SETSCROLLTIME = TV_FIRST + 33,
///
/// Retrieves the maximum scroll time for the tree-view control. You can send this message explicitly or by using the
/// TreeView_GetScrollTime macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the maximum scroll time, in milliseconds.
///
///
/// The maximum scroll time is the longest amount of time that a scroll operation can take. The scrolling will be adjusted so
/// that the scroll will take place within the maximum scroll time. A scroll operation may take less time than the maximum.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getscrolltime
TVM_GETSCROLLTIME = TV_FIRST + 34,
///
/// Sets the color used to draw the insertion mark for the tree view. You can send this message explicitly or by using the
/// TreeView_SetInsertMarkColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// COLORREF value that contains the new insertion mark color.
/// Returns
/// Returns a COLORREF value that contains the previous insertion mark color.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setinsertmarkcolor
TVM_SETINSERTMARKCOLOR = TV_FIRST + 37,
///
/// Retrieves the color used to draw the insertion mark for the tree view. You can send this message explicitly or by using the
/// TreeView_GetInsertMarkColor macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns a COLORREF value that contains the current insertion mark color.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getinsertmarkcolor
TVM_GETINSERTMARKCOLOR = TV_FIRST + 38,
///
/// Intended for internal use; not recommended for use in applications.
///
/// Sets the size of the border for the items in a tree-view control. You can send the message explicitly or by using the
/// TreeView_SetBorder macro.
///
/// Parameters
/// wParam
/// Action flags. This parameter can be one or more of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// TVSBF_XBORDER
/// Applies the specified border size to the left side of the items in the tree-view control.
///
/// -
/// TVSBF_YBORDER
/// Applies the specified border size to the top of the items in the tree-view control.
///
///
/// lParam
///
/// The LOWORD is a SHORT that specifies the size of the left border, in pixels. The HIWORD is a
/// SHORT that specifies the size of the top border, in pixels.
///
/// Returns
///
/// Returns a LONG value that contains the previous border size, in pixels. The LOWORD contains the previous size
/// of the horizontal border, and the HIWORD contains the previous size of the vertical border.
///
///
///
/// Security Warning: Using this message might compromise the security of your program.
/// The item border is set just for spacing purposes. A successful setting triggers a recalculation of the scroll bars.
///
/// This message may not be supported in future versions of Comctl32.dll. Also, this message is not defined in commctrl.h. Add
/// the following definitions to the source files of your application to use the message:
///
///
/// #define TVM_SETBORDER (TV_FIRST + 35) #define TVSBF_XBORDER 0x00000001 #define TVSBF_YBORDER 0x00000002
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setborder
TVM_SETBORDER = TV_FIRST + 35,
///
/// Retrieves some or all of a tree-view item's state attributes. You can send this message explicitly or by using the
/// TreeView_GetItemState macro.
/// Parameters
/// wParam
/// Handle to the item.
/// lParam
/// Mask used to specify the states to query for. It is equivalent to the stateMask member of TVITEMEX.
/// Returns
///
/// Returns a UINT value with the appropriate state bits set to TRUE. Only those bits that are specified by lParam
/// and that are TRUE will be set. This value is equivalent to the state member of TVITEMEX.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getitemstate
TVM_GETITEMSTATE = TV_FIRST + 39,
/// The TVM_SETLINECOLOR message sets the current line color.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// New line color. Use the CLR_DEFAULT value to restore the system default colors.
/// Returns
/// Returns the previous line color.
///
///
/// This message only changes line colors. To change the colors of the '+' and '-' inside the buttons, use the
/// TVM_SETTEXTCOLOR message.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setlinecolor
TVM_SETLINECOLOR = TV_FIRST + 40,
/// The TVM_GETLINECOLOR message gets the current line color.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the current line color, or the CLR_DEFAULT value if none has been specified.
///
///
/// This message only retrieves line colors. To retrieve the colors of the '+' and '-' inside the buttons, use the
/// TVM_GETTEXTCOLOR message.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getlinecolor
TVM_GETLINECOLOR = TV_FIRST + 41,
/// Maps an accessibility ID to an HTREEITEM.
/// Parameters
/// wParam
/// **UINT** that contains the accessibility ID to map to an **HTREEITEM**.
/// lParam
/// Must be zero.
/// Returns
/// Returns the HTREEITEM that the specified accessibility ID is mapped to.
///
///
/// When you add an item to a tree-view control an HTREEITEM returns, which uniquely identifies the item.
///
/// Note
///
/// To use this message, you must provide a manifest specifying Comclt32.dll version 6.0. For more information on manifests, see
/// Enabling Visual Styles.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-mapaccidtohtreeitem
TVM_MAPACCIDTOHTREEITEM = TV_FIRST + 42,
/// Maps an HTREEITEM to an accessibility ID.
/// Parameters
/// wParam
/// **HTREEITEM** that is mapped to an accessibility ID.
/// lParam
/// Must be zero.
/// Returns
/// Returns an accessibility ID.
///
///
/// When you add an item to a tree-view control an HTREEITEM handle is returned that uniquely identifies the item.
///
/// Note
///
/// To use this message, you must provide a manifest specifying Comclt32.dll version 6.0. For more information on manifests, see
/// Enabling Visual Styles.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-maphtreeitemtoaccid
TVM_MAPHTREEITEMTOACCID = TV_FIRST + 43,
/// Informs the tree-view control to set extended styles. Send this message or use the macro TreeView_SetExtendedStyle.
/// Parameters
/// wParam
/// Mask used to select the styles to be set.
/// lParam
/// Value that indicates the extended style. For more information on styles, see Tree-View Control Extended Styles.
/// Returns
/// If this message succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
///
/// The extended styles for a tree-view control have nothing to do with the extended styles used with function
/// CreateWindowEx or function SetWindowLong.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setextendedstyle
TVM_SETEXTENDEDSTYLE = TV_FIRST + 44,
///
/// Retrieves the extended style for a tree-view control. Send this message explicitly or by using the
/// TreeView_GetExtendedStyle macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Must be zero.
/// Returns
/// Returns the value of extended style.For more information on styles, see Tree-View Control Extended Styles.
///
///
/// The extended styles for a tree-view control have nothing to do with the extended styles used with function
/// CreateWindowEx or function SetWindowLong.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getextendedstyle
TVM_GETEXTENDEDSTYLE = TV_FIRST + 45,
///
/// Inserts a new item in a tree-view control. You can send this message explicitly or by using the TreeView_InsertItem macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Pointer to a TVINSERTSTRUCT structure that specifies the attributes of the tree-view item.
/// Returns
/// Returns the HTREEITEM handle to the new item if successful, or NULL otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-insertitem
TVM_INSERTITEM = TV_FIRST + 50,
///
/// Sets information used to determine auto-scroll characteristics. You can send this message explicitly or by using the
/// TreeView_SetAutoScrollInfo macro.
/// Parameters
/// wParam
/// Specifies pixels per second. The offset to scroll is divided by the wParam to determine the total duration of the auto-scroll.
/// lParam
///
/// Specifies the redraw time interval. Redraw at every elasped interval, until the item is scrolled into view. Given wParam, the
/// location of the item is calculated and a repaint occurs. Set this value to create smooth scrolling.
///
/// Returns
/// Returns TRUE.
///
///
/// Autoscroll information is used to scroll a nonvisible item into view. The control must have the TVS_EX_AUTOHSCROLL
/// extended style. For information on extended styles, see Tree-View Control Extended Styles.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setautoscrollinfo
TVM_SETAUTOSCROLLINFO = TV_FIRST + 59,
///
///
/// [Intended for internal use; not recommended for use in applications. This message may not be supported in future versions of Windows.]
///
///
/// Sets the hot item for a tree-view control. You can send this message explicitly or by using the TreeView_SetHot macro.
///
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Handle to the new hot item. If this value is NULL, the tree-view control will be set to have no hot item.
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The hot item is the item that the mouse is hovering over. This message makes an item look like it is the hot item even if the
/// mouse is not hovering over it.
///
/// This message has no visible effect if the TVS_TRACKSELECT style is not set.
/// If it succeeds, this message causes the hot item to be redrawn.
/// This message is ignored if lParam is NULL and the tree-view control is tracking the mouse.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-sethot
TVM_SETHOT = TV_FIRST + 58,
///
/// Retrieves some or all of a tree-view item's attributes. You can send this message explicitly or by using the
/// TreeView_GetItem macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// Pointer to a TVITEM structure that specifies the information to retrieve and receives information about the item. With
/// version 4.71 and later, you can use a TVITEMEX structure instead.
///
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// When the message is sent, the hItem member of the TVITEM or TVITEMEX structure identifies the item to
/// retrieve information about, and the mask member specifies the attributes to retrieve.
///
///
/// If the TVIF_TEXT flag is set in the mask member of the TVITEM or TVITEMEX structure, the pszText
/// member must point to a valid buffer and the cchTextMax member must be set to the number of characters in that buffer.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getitem
TVM_GETITEM = TV_FIRST + 62,
///
/// The TVM_SETITEM message sets some or all of a tree-view item's attributes. You can send this message explicitly or by
/// using the TreeView_SetItem macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
///
/// Pointer to a TVITEM structure that contains the new item attributes. With version 4.71 and later, you can use a
/// TVITEMEX structure instead.
///
/// Returns
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// The hItem member of the TVITEM or TVITEMEX structure identifies the item, and the mask member
/// specifies which attributes to set.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-setitem
TVM_SETITEM = TV_FIRST + 63,
///
/// Retrieves the incremental search string for a tree-view control. The tree-view control uses the incremental search string to
/// select an item based on characters typed by the user. You can send this message explicitly or by using the
/// TreeView_GetISearchString macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Pointer to the buffer that receives the incremental search string.
/// Returns
/// Returns the number of characters in the incremental search string.
///
///
///
/// Security Warning: Using this message incorrectly might compromise the security of your program. You must allocate a
/// large enough buffer to hold the string. First call the message passing NULL in lParam. This returns the number of
/// characters, excluding NULL, that are required. Then call the message a second time to retrieve the string. You should
/// review Security Considerations: Microsoft Windows Controls before continuing.
///
/// If the tree-view control is not in incremental search mode, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getisearchstring
TVM_GETISEARCHSTRING = TV_FIRST + 64,
///
/// 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. This message implicitly selects and focuses the specified item. You can send this message explicitly or
/// by using the TreeView_EditLabel macro.
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Handle to the item to edit.
/// Returns
/// Returns the handle to the edit control used to edit the item text if successful, or NULL otherwise.
///
///
/// This message sends a TVN_BEGINLABELEDIT notification code to the parent of the tree-view control.
///
/// When the user completes or cancels editing, the edit control is destroyed and the handle is no longer valid. You can subclass
/// the edit control, but do not destroy it.
///
///
/// The control must have the focus before you send this message to the control. Focus can be set using the SetFocus function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-editlabel
TVM_EDITLABEL = TV_FIRST + 65,
/// This message is not implemented.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getselectedcount
TVM_GETSELECTEDCOUNT = TV_FIRST + 70,
///
/// Shows the infotip for a specified item in a tree-view control. You can send this message explicitly or by using the
/// TreeView_ShowInfoTip macro..
/// Parameters
/// wParam
/// Must be zero.
/// lParam
/// Handle to the item.
/// Returns
/// Returns zero.
///
///
/// Most applications do not use this message. Infotips are shown automatically. For more information, see Using Tree-view
/// Infotips in the About Tree-View Controls overview.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-showinfotip
TVM_SHOWINFOTIP = TV_FIRST + 71,
/// This message is not implemented.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvm-getitempartrect
TVM_GETITEMPARTRECT = TV_FIRST + 72,
}
/// Tree View Notifications
[PInvokeData("Commctrl.h", MSDNShortId = "ff486107")]
public enum TreeViewNotification
{
///
///
/// Sent by a tree-view control to its parent when the drawing of a icon or overlay has failed. This notification code is sent in
/// the form of a WM_NOTIFY message.
///
///
/// TVN_ASYNCDRAW pnmTVAsynchDraw = (NMTVASYNCDRAW *) lParam;
///
/// Parameters
/// lParam
/// Pointer to an NMTVASYNCDRAW structure. The NMTVASYNCDRAW structure contains the reason the draw failed.
/// Returns
/// No return value.
///
///
///
/// The tree-view control must have the TVS_EX_DRAWIMAGEASYNC extended style. Note that this is equivalent to list-view's
/// LVN_ASYNCDRAWN flag and its corresponding style.
///
///
/// This control does not draw asynchronously. Asynchronous is used in the context that the tree-view control does not
/// synchronously extract an image if it is not available. (For instance, the image may not be available if the tree-view control
/// uses a sparse image list, since the image may be unloaded.) Instead, when an image is not available, the control
/// synchronously asks the parent what action to take by sending the parent an TVN_ASYNCDRAW notification with a
/// NMTVASYNCDRAW structure. The hr member of this structure describes the reason the control's draw failed. An
/// hr result of E_PENDING means the image is not present at all (the image needs to be extracted). Success indicates that
/// the image is present but not at the required image quality.
///
///
/// The parent sets the dwRetFlags member of the structure to inform the control how to proceed. For instance, the parent
/// may return another image, in the iRetImageIndex member, for the control to draw. In this case, the parent sets the
/// dwRetFlags member to ADRF_DRAWIMAGE. If the control finds the returned image has not been extracted, yet another
/// TVN_ASYNCDRAW notification may be sent by the control.
///
///
/// If an image is not available, the idea behind asynchronous is to allow the parent do the extraction in the background so that
/// extraction does not block the UI thread, that is, the thread the control is on. The parent may return ADRF_DRAWNOTHING to the
/// control, then launch a background thread to extract the icon. Once extracted, the parent may set the icon in the treeview
/// control with macro TreeView_SetItem. This causes tree-view to invalidate the item and eventually repaint it with the
/// extracted image in the image list.
///
///
/// The following code example, to be used as part of a larger program, shows how a parent may process two possible return codes
/// in this notification by a control, and decide what action the control should take. Setting dwRetFlags is not shown.
///
///
/// case TVN_ASYNCDRAW: NMTVASYNCDRAW *pnm = (NMTVASYNCDRAW *)lParam short dwDrawSuccessFlags = ShortFromResult(pnm->hr); if (dwDrawSuccessFlags & ILDRF_IMAGELOWQUALITY) { // Need to re-extract the icon } if (dwDrawSuccessFlags & ILDRF_OVERLAYLOWQUALITY) { // Need to re-extract the overlay }
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-asyncdraw
TVN_ASYNCDRAW = TVN_FIRST - 20,
///
///
/// Notifies a tree-view control's parent window that a drag-and-drop operation involving the left mouse button is being
/// initiated. This notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_BEGINDRAG pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemNew member is a TVITEM structure that contains valid
/// information about the item being dragged in the hItem, state, and lParam members. The ptDrag
/// member specifies the current screen coordinates of the mouse.
///
/// Returns
/// The return value is ignored.
///
/// A tree-view control that has the TVS_DISABLEDRAGDROP style does not send this notification code.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-begindrag
TVN_BEGINDRAG = TVN_FIRST - 56,
///
///
/// Notifies a tree-view control's parent window about the start of label editing for an item. This notification code is sent in
/// the form of a WM_NOTIFY message.
///
///
/// TVN_BEGINLABELEDIT ptvdi = (LPNMTVDISPINFO) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTVDISPINFO structure. The item member is a TVITEM structure that contains valid
/// information about the item being edited in the hItem, state, lParam, and pszText members.
///
/// Returns
/// Returns TRUE to cancel label editing.
///
///
///
/// When label editing begins, an edit control is created but not positioned or displayed. Before it is displayed, the tree-view
/// control sends its parent window a TVN_BEGINLABELEDIT notification code.
///
///
/// To customize label editing, implement a handler for TVN_BEGINLABELEDIT and have it send a TVM_GETEDITCONTROL message
/// to the tree-view control. If a label is being edited, the return value will be a handle to the edit control. Use this handle
/// to customize the edit control by sending the usual EM_XXX messages.
///
/// When the user cancels or completes the editing, the parent window receives a TVN_ENDLABELEDIT notification code.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-beginlabeledit
TVN_BEGINLABELEDIT = TVN_FIRST - 59,
///
///
/// Notifies a tree-view control's parent window about the initiation of a drag-and-drop operation involving the right mouse
/// button. This notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_BEGINRDRAG pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemNew member is a TVITEM structure that contains valid
/// information in the hItem, state, and lParam members about the item to be dragged. The ptDrag
/// member specifies the current screen coordinates of the mouse.
///
/// Returns
/// The return value is ignored.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-beginrdrag
TVN_BEGINRDRAG = TVN_FIRST - 57,
///
///
/// Notifies a tree-view control's parent window that an item is being deleted. This notification code is sent in the form of a
/// WM_NOTIFY message.
///
///
/// TVN_DELETEITEM pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemOld member is a TVITEM structure whose hItem and
/// lParam members contain valid information about the item being deleted.
///
/// Returns
/// The return value is ignored.
///
///
/// If the lParam member of the TVITEM structure points to memory allocated by your application, you can free it
/// when you receive the TVN_DELETEITEM notification code.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-deleteitem
TVN_DELETEITEM = TVN_FIRST - 58,
///
///
/// Notifies a tree-view control's parent window about the end of label editing for an item. This notification code is sent in
/// the form of a WM_NOTIFY message.
///
///
/// TVN_ENDLABELEDIT ptvdi = (LPNMTVDISPINFO) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTVDISPINFO structure. The item member of this structure is a TVITEM structure whose
/// hItem, lParam, and pszText members contain valid information about the item that was edited. If label
/// editing was canceled, the pszText member of the TVITEM structure is NULL; otherwise, pszText is
/// the address of the edited text.
///
/// Returns
///
/// If the pszText member is non- NULL, return TRUE to set the item's label to the edited text. Return
/// FALSE to reject the edited text and revert to the original label.
///
///
///
/// If the pszText member is NULL, the return value is ignored.
///
/// If you specified the LPSTR_TEXTCALLBACK value for this item and the pszText member is non- NULL, your
/// TVN_ENDLABELEDIT handler should copy the text from pszText to your local storage.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-endlabeledit
TVN_ENDLABELEDIT = TVN_FIRST - 60,
///
///
/// Requests that a tree-view control's parent window provide information needed to display or sort an item. This notification
/// code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_GETDISPINFO lptvdi = (LPNMTVDISPINFO) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTVDISPINFO structure. The item member is a TVITEM structure whose mask,
/// hItem, state, and lParam members specify the type of information required. You must fill the members of
/// the structure with the appropriate information.
///
/// Returns
/// The return value is ignored.
///
///
/// This notification code is sent under the following circumstances:
///
/// -
///
/// If the pszText member of the item's TVITEM structure is the LPSTR_TEXTCALLBACK value, the control sends this
/// notification code to retrieve the item's text. In this case, the mask member of lParam will have the TVIF_TEXT flag set.
///
///
/// -
///
/// If the iImage or iSelectedImage member of the item's TVITEM structure is the I_IMAGECALLBACK value, the
/// control sends this notification code to retrieve the index of an item's icons in the control's image list. In this case, if
/// the item is selected, the mask member of lParam will have the TVIF_SELECTEDIMAGE flag set. If the item is not
/// selected, the mask member of lParam will have the TVIF_IMAGE flag set.
///
///
/// -
///
/// If the cChildren member of the item's TVITEM structure is the I_CHILDRENCALLBACK value, the control sends this
/// notification code to retrieve a value that indicates whether the item has child items. In this case, the mask member
/// of lParam will have the TVIF_CHILDREN flag set.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-getdispinfo
TVN_GETDISPINFO = TVN_FIRST - 52,
///
///
/// Sent by a tree-view control that has the TVS_INFOTIP style. This notification code is sent when the control is
/// requesting additional text information to be displayed in a tooltip. The notification code is sent in the form of a
/// WM_NOTIFY message.
///
///
/// TVN_GETINFOTIP lpGetInfoTip = (LPNMTVGETINFOTIP)lParam;
///
/// Parameters
/// lParam
/// Pointer to an NMTVGETINFOTIP structure that contains information about this notification code.
/// Returns
/// The control ignores the return value for this notification code.
///
/// This notification code is only sent by tree-view controls that have the TVS_INFOTIP style.
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-getinfotip
TVN_GETINFOTIP = TVN_FIRST - 14,
///
///
/// Notifies a tree-view control's parent window that item attributes have changed. This notification code is sent in the form of
/// a WM_NOTIFY message.
///
///
/// TVN_ITEMCHANGED pnm = (NMTVITEMCHANGE *) lParam;
///
/// Parameters
/// lParam
///
/// Pointer to a NMTVITEMCHANGE structure describing the item that changed. The uChanged member is set to TVIF_STATE.
///
/// Returns
/// Returns FALSE to accept the change, or TRUE to prevent the change.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-itemchanged
TVN_ITEMCHANGED = TVN_FIRST - 19,
///
///
/// Notifies a tree-view control's parent window that item attributes are about to change. This notification code is sent in the
/// form of a WM_NOTIFY message.
///
///
/// TVN_ITEMCHANGING pnm = (NMTVITEMCHANGE *) lParam;
///
/// Parameters
/// lParam
///
/// Pointer to an NMTVITEMCHANGE structure describing the item that is changing. The uChanged member is set to TVIF_STATE.
///
/// Returns
/// Returns FALSE to accept the change, or TRUE to prevent the change.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-itemchanging
TVN_ITEMCHANGING = TVN_FIRST - 17,
///
///
/// Notifies a tree-view control's parent window that a parent item's list of child items has expanded or collapsed. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_ITEMEXPANDED pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemNew member is a TVITEM structure that contains valid
/// information about the parent item in the hItem, state, and lParam members. The action member
/// indicates whether the list expanded or collapsed. For a list of possible values, see the description of the TVM_EXPAND message.
///
/// Returns
/// The return value is ignored.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-itemexpanded
TVN_ITEMEXPANDED = TVN_FIRST - 55,
///
///
/// Notifies a tree-view control's parent window that a parent item's list of child items is about to expand or collapse. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_ITEMEXPANDING pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemNew member is a TVITEM structure that contains valid
/// information about the parent item in the hItem, state, and lParam members. The action member
/// indicates whether the list is to expand or collapse. For a list of possible values, see the description of the
/// TVM_EXPAND message.
///
/// Returns
/// Returns TRUE to prevent the list from expanding or collapsing.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-itemexpanding
TVN_ITEMEXPANDING = TVN_FIRST - 54,
///
///
/// Notifies a tree-view control's parent window that the user pressed a key and the tree-view control has the input focus. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_KEYDOWN ptvkd = (LPNMTVKEYDOWN) lParam
///
/// Parameters
/// lParam
/// Pointer to an NMTVKEYDOWN structure. The wVKey member specifies the virtual key code.
/// Returns
///
/// If the wVKey member of lParam is a character key code, the character will be used as part of an incremental search.
/// Return nonzero to exclude the character from the incremental search, or zero to include the character in the search. For all
/// other keys, the return value is ignored.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-keydown
TVN_KEYDOWN = TVN_FIRST - 12,
///
///
/// Notifies a tree-view control's parent window that the selection has changed from one item to another. This notification code
/// is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_SELCHANGED pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemOld and itemNew members of the NMTREEVIEW structure
/// are TVITEM structures that contain information about the previously selected item and the newly selected item. Only
/// the mask, hItem, state, and lParam members of these structures are valid. The stateMask
/// members of the TVITEM structures specified by itemOld and itemNew are undefined on input. The
/// action member of the NMTREEVIEW structure indicates the type of action that caused the selection to change. It
/// can be one of the following values:
///
///
///
/// Requirement
/// Value
///
/// -
/// TVC_BYKEYBOARD
/// By a keystroke.
///
/// -
/// TVC_BYMOUSE
/// By a mouse click.
///
/// -
/// TVC_UNKNOWN
/// Unknown.
///
///
/// Returns
/// The return value is ignored.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-selchanged
TVN_SELCHANGED = TVN_FIRST - 51,
///
///
/// Notifies a tree-view control's parent window that the selection is about to change from one item to another. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_SELCHANGING pnmtv = (LPNMTREEVIEW) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTREEVIEW structure. The itemOld and itemNew members contain valid information about the
/// currently selected item and the newly selected item. The action member indicates whether a mouse or keyboard action is
/// causing the selection to change. For a list of possible values, see the description of the TVN_SELCHANGED notification code.
///
/// Returns
/// Returns TRUE to prevent the selection from changing.
///
///
/// When responding to this notification code, applications should not delete the items that are gaining or losing the selection.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-selchanging
TVN_SELCHANGING = TVN_FIRST - 50,
///
///
/// Notifies a tree-view control's parent window that it must update the information it maintains about an item. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_SETDISPINFO lptvdi = (LPNMTVDISPINFO) lParam
///
/// Parameters
/// lParam
///
/// Pointer to an NMTVDISPINFO structure that describes the item being updated. The hItem member of the
/// TVITEM structure specifies the item being updated, and the mask member specifies which attributes of the item
/// are being updated.
///
/// Returns
/// The return value is ignored.
///
///
///
/// If the pszText member of the item's TVITEM structure is the LPSTR_TEXTCALLBACK value, the control sends this
/// notification to set the item's text. In this case, the mask member of lParam will have the TVIF_TEXT flag set.
///
///
/// If the iImage or iSelectedImage member of the item's TVITEM structure is the I_IMAGECALLBACK value, the
/// control sends this notification to retrieve the index of the icon image to display. In this case, the mask member of
/// lParam will have the TVIF_IMAGE or TVIF_SELECTEDIMAGE flag set.
///
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-setdispinfo
TVN_SETDISPINFO = TVN_FIRST - 53,
///
///
/// Sent by a tree-view control with the TVS_SINGLEEXPAND style when the user opens or closes a tree item using a single
/// click of the mouse. This notification code is sent in the form of a WM_NOTIFY message.
///
///
/// TVN_SINGLEEXPAND lpnmtv = (LPNMTREEVIEW)lParam;
///
/// Parameters
/// lParam
/// Pointer to an NMTREEVIEW structure that contains information about this notification code.
/// Returns
/// Return TVNRET_DEFAULT to allow the default behavior to occur. To modify the default behavior, return:
///
///
/// Return code
/// Description
///
/// -
/// TVNRET_SKIPOLD
/// Skip default processing of the item being unselected.
///
/// -
/// TVNRET_SKIPNEW
/// Skip default processing of the item being selected.
///
///
///
///
///
/// To skip default processing of selected and unselected items, return both TVNRET_SKIPOLD and TVNRET_SKIPNEW by combining them
/// with a logical OR.
///
/// This notification code is only sent by tree-view controls that have the TVS_SINGLEEXPAND style.
///
// https://docs.microsoft.com/en-us/windows/win32/controls/tvn-singleexpand
TVN_SINGLEEXPAND = TVN_FIRST - 15,
}
/// Used as return values to the TVN_SINGLEEXPAND notification.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773553")]
public enum TreeViewNotificationReturnBehavior
{
/// Allow the default behavior to occur.
TVNRET_DEFAULT = 0,
/// Skip default processing of the item being unselected.
TVNRET_SKIPOLD = 1,
/// Skip default processing of the item being selected.
TVNRET_SKIPNEW = 2,
}
/// Used in the action member coming through the lParam of a TVN_SELCHANGED notification.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773544")]
public enum TreeViewSelChangedCause
{
/// Unknown.
TVC_UNKNOWN = 0x0000,
/// By a mouse click.
TVC_BYMOUSE = 0x0001,
/// By a keystroke.
TVC_BYKEYBOARD = 0x0002,
}
/// Used as the wParam value in a TVM_SETBORDER message.
[PInvokeData("Commctrl.h", MSDNShortId = "ee663567")]
[Flags]
public enum TreeViewSetBorderFlags
{
/// Applies the specified border size to the left side of the items in the tree-view control.
TVSBF_XBORDER = 0x00000001,
/// Applies the specified border size to the top of the items in the tree-view control.
TVSBF_YBORDER = 0x00000002,
}
/// Used as the wParam value in a TVM_SETIMAGELIST and TVM_GETIMAGELIST messages.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773747")]
public enum TreeViewSetImageListType
{
///
/// Indicates the normal image list, which contains selected, nonselected, and overlay images for the items of a tree-view control.
///
TVSIL_NORMAL = 0,
///
/// 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.
///
TVSIL_STATE = 2
}
/// Window styles used when creating tree-view controls.
[PInvokeData("Commctrl.h", MSDNShortId = "bb760013")]
[Flags]
public enum TreeViewStyle
{
///
/// Version 4.70. Enables check boxes for items in a tree-view control. A check box is displayed only if an image is associated
/// with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list
/// containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to
/// zero removes the check box altogether. For more information, see Working with state image indexes.
/// Version 5.80. Displays a check box even if no image is associated with the item.
///
/// 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. Destroying the tree-view control does not destroy the check box state image list. You must
/// destroy it explicitly. Get the handle to the state image list by sending the tree-view control a TVM_GETIMAGELIST message.
/// Then destroy the image list with ImageList_Destroy.
///
///
/// If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview
/// control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.
///
///
TVS_CHECKBOXES = 0x0100,
/// Prevents the tree-view control from sending TVN_BEGINDRAG notification codes.
TVS_DISABLEDRAGDROP = 0x0010,
/// Allows the user to edit the labels of tree-view items.
TVS_EDITLABELS = 0x0008,
///
/// Version 4.71. 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_FULLROWSELECT = 0x1000,
///
/// 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_HASBUTTONS = 0x0001,
/// Uses lines to show the hierarchy of items.
TVS_HASLINES = 0x0002,
/// Version 4.71. Obtains tooltip information by sending the TVN_GETINFOTIP notification.
TVS_INFOTIP = 0x0800,
///
/// 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_LINESATROOT = 0x0004,
///
/// Version 5.80. Disables horizontal scrolling in the control. The control will not display any horizontal scroll bars.
///
TVS_NOHSCROLL = 0x8000,
///
/// Version 4.71 Sets the height of the items to an odd height with the TVM_SETITEMHEIGHT message. By default, the height of
/// items must be an even value.
///
TVS_NONEVENHEIGHT = 0x4000,
///
/// Version 4.71. Disables both horizontal and vertical scrolling in the control. The control will not display any scroll bars.
///
TVS_NOSCROLL = 0x2000,
/// Version 4.70. Disables tooltips.
TVS_NOTOOLTIPS = 0x0080,
///
/// Version 4.70. 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_RTLREADING = 0x0040,
/// Causes a selected item to remain selected when the tree-view control loses focus.
TVS_SHOWSELALWAYS = 0x0020,
///
/// Version 4.71. 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.
///
/// Version 5.80. Causes the item being selected to expand and the item being unselected to collapse upon selection in the tree
/// view. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed.
///
///
TVS_SINGLEEXPAND = 0x0400,
/// Version 4.70. Enables hot tracking in a tree-view control.
TVS_TRACKSELECT = 0x0200,
}
///
/// Extended styles used when creating tree-view controls. The value of extended styles is a bitwise combination of these styles.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb759981")]
[Flags]
public enum TreeViewStyleEx
{
/// Windows Vista. Remove the horizontal scroll bar and auto-scroll depending on mouse position.
TVS_EX_AUTOHSCROLL = 0x0020,
/// Windows Vista. Include dimmed checkbox state if the control has the TVS_CHECKBOXES style.
TVS_EX_DIMMEDCHECKBOXES = 0x0200,
/// Windows Vista. Specifies how the background is erased or filled.
TVS_EX_DOUBLEBUFFER = 0x0004,
/// Windows Vista. Retrieves calendar grid information.
TVS_EX_DRAWIMAGEASYNC = 0x0400,
/// Windows Vista. Include exclusion checkbox state if the control has the TVS_CHECKBOXES style.
TVS_EX_EXCLUSIONCHECKBOXES = 0x0100,
///
/// Windows Vista. Fade expando buttons in or out when the mouse moves away or into a state of hovering over the control.
///
TVS_EX_FADEINOUTEXPANDOS = 0x0040,
/// Not supported. Do not use.
TVS_EX_MULTISELECT = 0x0002,
/// Windows Vista. Do not indent the tree view for the expando buttons.
TVS_EX_NOINDENTSTATE = 0x0008,
///
/// Windows Vista. 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.
/// This style may not be supported in future versions of Comctl32.dll. Also, this style is not defined in commctrl.h.
///
TVS_EX_NOSINGLECOLLAPSE = 0x0001,
/// Windows Vista. Include partial checkbox state if the control has the TVS_CHECKBOXES style.
TVS_EX_PARTIALCHECKBOXES = 0x0080,
/// Windows Vista. Allow rich tooltips in the tree view (custom drawn with icon and text).
TVS_EX_RICHTOOLTIP = 0x0010,
}
/// Tree view button item part.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773442")]
public enum TVITEMPART
{
/// Button item part.
TVGIPR_BUTTON = 0x0001,
}
/// Provides a handle to a tree view item.
[StructLayout(LayoutKind.Sequential)]
public struct HTREEITEM
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTREEITEM(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTREEITEM NULL => new HTREEITEM(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTREEITEM h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTREEITEM(IntPtr h) => new HTREEITEM(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTREEITEM h1, HTREEITEM h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTREEITEM h1, HTREEITEM h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTREEITEM h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
}
///
/// Contains information about a tree-view notification message. This structure is identical to the NM_TREEVIEW structure, but it has
/// been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773411")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTREEVIEW
{
/// NMHDR structure that contains information about this notification message.
public NMHDR hdr;
///
/// Notification-specific action flag. This member is used with the following notification codes: TVN_ITEMEXPANDING,
/// TVN_ITEMEXPANDED, TVN_SELCHANGING, TVN_SELCHANGED. For the possible action flag values, see TVM_EXPAND and TVN_SELCHANGED.
///
public int action;
///
/// TVITEM structure that contains information about the old item state. This member is zero for notification messages that do
/// not use it.
///
public TVITEM itemOld;
///
/// TVITEM structure that contains information about the new item state. This member is zero for notification messages that do
/// not use it.
///
public TVITEM itemNew;
///
/// POINT structure that contains the client coordinates of the mouse at the time the event occurred that caused the notification
/// message to be sent.
///
public POINT ptDrag;
}
///
/// Contains an explanation of why the draw of an icon or overlay tree item failed. This structure is sent on a TVN_ASYNCDRAW
/// notification. Set the dwRetFlags member to indicate what action the control should take. Note that a draw can fail if there is no
/// image; in other words, when the icon image has not been extracted.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773413")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTVASYNCDRAW
{
/// NMHDR structure.
public NMHDR hdr;
/// IMAGELISTDRAWPARAMS structure describing the image that failed to draw.
public IMAGELISTDRAWPARAMS pimldp;
///
/// Result code indicating why the draw failed, either ILDRF_IMAGELOWQUALITY, ILDRF_OVERLAYLOWQUALITY, E_PENDING, or S_OK. A code
/// of S_OK indicates that the image is present but not at the required image quality.
///
public HRESULT hr;
/// Handle of the tree item that failed to draw.
public HTREEITEM hItem;
///
/// Data for hItem. This is the same data for the item that is retrieved with the message TVM_GETITEM using the appropriate mask
/// in structure TVITEM. This data is parent specific; the parent can store information that helps it identify the tree item or
/// other information. Data is provided in lParam for convenience, so that the parent does not need to send message TVM_GETITEM.
///
public IntPtr lParam;
/// Action that the sender (the tree-view control) should execute on return.
public AsyncDrawRetFlags dwRetFlags;
/// Index of the image to draw in the image list. Used if ADRF_DRAWIMAGE is returned in dwRetFlags.
public int iRetImageIndex;
}
/// Contains information specific to an NM_CUSTOMDRAW (tree view) notification code sent by a tree-view control.
[PInvokeData("Commctrl.h", MSDNShortId = "bb773415")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTVCUSTOMDRAW
{
/// NMCUSTOMDRAW structure that contains general custom draw information.
public NMCUSTOMDRAW nmcd;
/// COLORREF value representing the color that will be used to display text foreground in the tree-view control.
public int clrText;
/// COLORREF value representing the color that will be used to display text background in the tree-view control.
public int clrTextBk;
///
/// Version 4.71. Zero-based level of the item being drawn. The root item is at level zero, a child of the root item is at level
/// one, and so on.
///
public int iLevel;
}
///
/// Contains and receives display information for a tree-view item. This structure is identical to the TV_DISPINFO structure, but it
/// has been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773418")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTVDISPINFO
{
/// NMHDR structure that contains information about this notification.
public NMHDR hdr;
///
/// TVITEM structure that identifies and contains information about the tree-view item. The mask member of the TVITEM structure
/// specifies which information is being set or retrieved.
///
public TVITEM item;
}
/// Contains information pertaining to extended TreeView notification information.
[PInvokeData("Commctrl.h", MSDNShortId = "bb760143")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTVDISPINFOEX
{
/// NMHDR structure that contains information about this notification.
public NMHDR hdr;
/// Specifies or receives attributes of a TreeView item.
public TVITEMEX item;
}
///
/// Contains and receives tree-view item information needed to display a tooltip for an item. This structure is used with the
/// TVN_GETINFOTIP notification code.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773421")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMTVGETINFOTIP
{
/// NMHDR structure that contains information about this notification.
public NMHDR hdr;
///
/// Address of a character buffer that contains the text to be displayed. If you want to change the text displayed in the
/// tooltip, you will need to modify the contents of this buffer. The size of this buffer is specified by the cchTextMax structure.
///
public StrPtrAuto pszText;
///
/// Size of the buffer at pszText, in characters. Although you should never assume that this buffer will be of any particular
/// size, the INFOTIPSIZE value can be used for design purposes.
///
public int cchTextMax;
/// Tree handle to the item for which the tooltip is being displayed.
public HTREEITEM hItem;
/// Application-defined data associated with the item for which the tooltip is being displayed.
public IntPtr lParam;
}
///
/// Contains information on a tree-view item change. This structure is sent with the TVN_ITEMCHANGED and TVN_ITEMCHANGING notifications.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773425")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMTVITEMCHANGE
{
/// NMHDR structure that contains information about the notification.
public NMHDR hdr;
///
/// Specifies the attribute. The only supported attribute is state. uChanged must have the following value: TVIF_STATE = The
/// change is the state attribute.
///
public TreeViewItemMask uChanged;
/// Handle to the changed tree-view item.
public HTREEITEM hItem;
/// Flag that specifies the new item state.
public TreeViewItemStates uStateNew;
/// Flag that specifies the item's previous state.
public TreeViewItemStates uStateOld;
/// Reserved for application specific data. For example, a value to associate with the item.
public IntPtr lParam;
}
///
/// Contains information about a keyboard event in a tree-view control. This structure is used with the TVN_KEYDOWN notification
/// code. The structure is identical to the TV_KEYDOWN structure, but it has been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773433")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTVKEYDOWN
{
/// NMHDR structure that contains information about this notification.
public NMHDR hdr;
/// Virtual key code.
public ushort wVKey;
/// Always zero.
public uint flags;
}
///
/// Contains information used to determine the location of a point relative to a tree-view control. This structure is used with the
/// TVM_HITTEST message. The structure is identical to the TV_HITTESTINFO structure, but it has been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773448")]
[StructLayout(LayoutKind.Sequential)]
public struct TVHITTESTINFO
{
/// Client coordinates of the point to test.
public POINT pt;
/// Variable that receives information about the results of a hit test.
public TreeViewHitTestFlags flags;
/// Handle to the item that occupies the point.
public HTREEITEM hItem;
}
///
/// Contains information used to add a new item to a tree-view control. This structure is used with the TVM_INSERTITEM message. The
/// structure is identical to the TV_INSERTSTRUCT structure, but it has been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773452")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct TVINSERTSTRUCT
{
///
/// Handle to the parent item. If this member is the TVI_ROOT value or NULL, the item is inserted at the root of the tree-view control.
///
public HTREEITEM hParent;
/// Handle to the item after which the new item is to be inserted, or one of the following values:
public HTREEITEM hInsertAfter;
/// Version 4.71. TVITEMEX structure that contains information about the item to add.
public TVITEMEX itemex;
}
///
/// Specifies or receives attributes of a tree-view item. This structure is identical to the TV_ITEM structure, but it has been
/// renamed to follow current naming conventions. New applications should use this structure.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773456")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct TVITEM
{
///
/// Array of flags that indicate which of the other structure members contain valid data. When this structure is used with the
/// TVM_GETITEM message, the mask member indicates the item attributes to retrieve. If used with the TVM_SETITEM message, the
/// mask indicates the attributes to set.
///
public TreeViewItemMask mask;
/// Handle to the item.
public HTREEITEM hItem;
///
/// Set of bit flags and image list indexes that indicate the item's state. When setting the state of an item, the stateMask
/// member indicates the valid bits of this member. When retrieving the state of an item, this member returns the current state
/// for the bits indicated in the stateMask member.
///
public uint state;
///
/// Bits of the state member that are valid. If you are retrieving an item's state, set the bits of the stateMask member to
/// indicate the bits to be returned in the state member. If you are setting an item's state, set the bits of the stateMask
/// member to indicate the bits of the state member that you want to set. To set or retrieve an item's overlay image index, set
/// the TVIS_OVERLAYMASK bits. To set or retrieve an item's state image index, set the TVIS_STATEIMAGEMASK bits.
///
public TreeViewItemStates stateMask;
///
/// Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is
/// the LPSTR_TEXTCALLBACK value, the parent window is responsible for storing the name. In this case, the tree-view control
/// sends the parent window a TVN_GETDISPINFO notification code when it needs the item text for displaying, sorting, or editing
/// and a TVN_SETDISPINFO notification code when the item text changes. If the structure is receiving item attributes, this
/// member is the address of the buffer that receives the item text. Note that although the tree-view control allows any length
/// string to be stored as item text, only the first 260 characters are displayed.
///
public IntPtr pszText;
///
/// Size of the buffer pointed to by the pszText member, in characters. If this structure is being used to set item attributes,
/// this member is ignored.
///
public int cchTextMax;
///
/// Index in the tree-view control's image list of the icon image to use when the item is in the nonselected state. If this
/// member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree-view
/// control sends the parent a TVN_GETDISPINFO notification code to retrieve the index when it needs to display the image.
///
public int iImage;
///
/// Index in the tree-view control's image list of the icon image to use when the item is in the selected state. If this member
/// is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree-view control
/// sends the parent a TVN_GETDISPINFO notification code to retrieve the index when it needs to display the image.
///
public int iSelectedImage;
///
/// Flag that indicates whether the item has associated child items. This member can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// zero
/// The item has no child items.
///
/// -
/// one
/// The item has one or more child items.
///
/// -
/// I_CHILDRENCALLBACK
///
/// The parent window keeps track of whether the item has child items.In this case, when the tree-view control needs to display
/// the item, the control sends the parent a TVN_GETDISPINFO notification code to determine whether the item has child items.
///
/// If the tree-view control has the TVS_HASBUTTONS style, it uses this member to determine whether to display the button
/// indicating the presence of child items. You can use this member to force the control to display the button even though the
/// item does not have any child items inserted. This allows you to display the button while minimizing the control's memory
/// usage by inserting child items only when the item is visible or expanded.
///
///
///
/// -
/// I_CHILDRENAUTO
///
/// Version 6.0 Intended for internal use; not recommended for use in applications.The tree-view control automatically determines
/// whether the item has child items. This flag may not be supported in future versions of Comctl32.dll.Also, this flag is
/// not defined in commctrl.h.Add the following definition to the source files of your application to use the flag:
///
/// #define I_CHILDRENAUTO (-2)
///
///
///
///
///
public int cChildren;
/// A value to associate with the item.
public IntPtr lParam;
/// Gets or sets a value indicating whether this is bold.
/// true if bold; otherwise, false.
public bool Bold
{
get => GetState(TreeViewItemStates.TVIS_BOLD); set => SetState(TreeViewItemStates.TVIS_BOLD, value);
}
/// Gets or sets a value indicating whether this is expanded.
/// true if expanded; otherwise, false.
public bool Expanded
{
get => GetState(TreeViewItemStates.TVIS_EXPANDED); set => SetState(TreeViewItemStates.TVIS_EXPANDED, value);
}
/// Gets or sets a value indicating whether child items have been expanded at least once.
/// true if child items have been expanded at least once; otherwise, false.
public bool ExpandedOnce
{
get => GetState(TreeViewItemStates.TVIS_EXPANDEDONCE); set => SetState(TreeViewItemStates.TVIS_EXPANDEDONCE, value);
}
/// Gets or sets a value indicating whether item is partially expanded.
/// true if partially expanded; otherwise, false.
public bool ExpandedPartial
{
get => GetState(TreeViewItemStates.TVIS_EXPANDPARTIAL); set => SetState(TreeViewItemStates.TVIS_EXPANDPARTIAL, value);
}
/// Gets or sets the index of the overlay image.
/// The index of the overlay image.
/// OverlayImageIndex - Overlay image index must be between 0 and 15
public uint OverlayImageIndex
{
get => (state & 0x00000F00) >> 8; set
{
if (value > 15)
throw new ArgumentOutOfRangeException(nameof(OverlayImageIndex), "Overlay image index must be between 0 and 15");
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= TreeViewItemStates.TVIS_OVERLAYMASK;
state = (value << 8) | (state & 0xFFFFF0FF);
}
}
/// Gets or sets a value indicating whether this is selected.
/// true if selected; otherwise, false.
public bool Selected
{
get => GetState(TreeViewItemStates.TVIS_SELECTED); set => SetState(TreeViewItemStates.TVIS_SELECTED, value);
}
/// Gets or sets a value indicating whether item is selected as part of a cut-and-paste operation.
/// true if item is selected as part of a cut-and-paste operation; otherwise, false.
public bool SelectedForCut
{
get => GetState(TreeViewItemStates.TVIS_CUT); set => SetState(TreeViewItemStates.TVIS_CUT, value);
}
/// Gets or sets a value indicating whether item is selected as a drag-and-drop target.
/// true if item is selected as a drag-and-drop target; otherwise, false.
public bool SelectedForDragDrop
{
get => GetState(TreeViewItemStates.TVIS_DROPHILITED); set => SetState(TreeViewItemStates.TVIS_DROPHILITED, value);
}
/// Gets the state.
/// The state.
public TreeViewItemStates State => (TreeViewItemStates)(state & 0x000000FF);
/// Gets or sets the index of the state image.
/// The index of the state image.
/// StateImageIndex - State image index must be between 0 and 15
public uint StateImageIndex
{
get => (state & 0x0000F000) >> 12; set
{
if (value > 15)
throw new ArgumentOutOfRangeException(nameof(StateImageIndex), "State image index must be between 0 and 15");
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= TreeViewItemStates.TVIS_STATEIMAGEMASK;
state = (value << 12) | (state & 0xFFFF0FFF);
}
}
/// Gets the text.
/// The text.
public string Text => pszText == LPSTR_TEXTCALLBACK ? null : Marshal.PtrToStringUni(pszText);
/// Gets or sets a value indicating whether to use text callback.
/// true if to use text callback; otherwise, false.
public bool UseTextCallback
{
get => pszText == LPSTR_TEXTCALLBACK;
set
{
if (value)
pszText = LPSTR_TEXTCALLBACK;
mask |= TreeViewItemMask.TVIF_TEXT;
}
}
/// Gets a value on whether the specified state is set.
/// State of the item.
/// true if the specified state is set; otherwise, false.
public bool GetState(TreeViewItemStates itemState) => State.IsFlagSet(itemState);
/// Sets the state of the specified state.
/// State of the item.
/// if set to true set this state on.
public void SetState(TreeViewItemStates itemState, bool on = true)
{
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= itemState;
var tempState = State;
EnumExtensions.SetFlags(ref tempState, itemState, on);
state = (uint)tempState | (state & 0xFFFFFF00);
}
/// Sets the text.
/// The managed string PTR.
/// Length of the string.
public void SetText(IntPtr managedStringPtr, int stringLen)
{
pszText = managedStringPtr;
cchTextMax = stringLen;
mask |= TreeViewItemMask.TVIF_TEXT;
}
/// Returns a that represents this instance.
/// A that represents this instance.
public override string ToString() => $"TVITEM: pszText={Text}; iImage={iImage}; iSelectedImage={iSelectedImage}; state={state}; cChildren={cChildren}";
}
///
/// Specifies or receives attributes of a tree-view item. This structure is an enhancement to the TVITEM structure. New applications
/// should use this structure where appropriate.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773459")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct TVITEMEX
{
///
/// Array of flags that indicate which of the other structure members contain valid data. When this structure is used with the
/// TVM_GETITEM message, the mask member indicates the item attributes to retrieve. If used with the TVM_SETITEM message, the
/// mask indicates the attributes to set.
///
public TreeViewItemMask mask;
/// Handle to the item.
public HTREEITEM hItem;
///
/// Set of bit flags and image list indexes that indicate the item's state. When setting the state of an item, the stateMask
/// member indicates the valid bits of this member. When retrieving the state of an item, this member returns the current state
/// for the bits indicated in the stateMask member.
///
public uint state;
///
/// Bits of the state member that are valid. If you are retrieving an item's state, set the bits of the stateMask member to
/// indicate the bits to be returned in the state member. If you are setting an item's state, set the bits of the stateMask
/// member to indicate the bits of the state member that you want to set. To set or retrieve an item's overlay image index, set
/// the TVIS_OVERLAYMASK bits. To set or retrieve an item's state image index, set the TVIS_STATEIMAGEMASK bits.
///
public TreeViewItemStates stateMask;
///
/// Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is
/// the LPSTR_TEXTCALLBACK value, the parent window is responsible for storing the name. In this case, the tree-view control
/// sends the parent window a TVN_GETDISPINFO notification code when it needs the item text for displaying, sorting, or editing
/// and a TVN_SETDISPINFO notification code when the item text changes. If the structure is receiving item attributes, this
/// member is the address of the buffer that receives the item text. Note that although the tree-view control allows any length
/// string to be stored as item text, only the first 260 characters are displayed.
///
public StrPtrAuto pszText;
///
/// Size of the buffer pointed to by the pszText member, in characters. If this structure is being used to set item attributes,
/// this member is ignored.
///
public int cchTextMax;
///
/// Index in the tree-view control's image list of the icon image to use when the item is in the nonselected state. If this
/// member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree-view
/// control sends the parent a TVN_GETDISPINFO notification code to retrieve the index when it needs to display the image.
///
public int iImage;
///
/// Index in the tree-view control's image list of the icon image to use when the item is in the selected state. If this member
/// is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree-view control
/// sends the parent a TVN_GETDISPINFO notification code to retrieve the index when it needs to display the image.
///
public int iSelectedImage;
///
/// Flag that indicates whether the item has associated child items. This member can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// zero
/// The item has no child items.
///
/// -
/// one
/// The item has one or more child items.
///
/// -
/// I_CHILDRENCALLBACK
///
/// The parent window keeps track of whether the item has child items.In this case, when the tree-view control needs to display
/// the item, the control sends the parent a TVN_GETDISPINFO notification code to determine whether the item has child items.
///
/// If the tree-view control has the TVS_HASBUTTONS style, it uses this member to determine whether to display the button
/// indicating the presence of child items. You can use this member to force the control to display the button even though the
/// item does not have any child items inserted. This allows you to display the button while minimizing the control's memory
/// usage by inserting child items only when the item is visible or expanded.
///
///
///
/// -
/// I_CHILDRENAUTO
///
/// Version 6.0 Intended for internal use; not recommended for use in applications.The tree-view control automatically determines
/// whether the item has child items. This flag may not be supported in future versions of Comctl32.dll.Also, this flag is
/// not defined in commctrl.h.Add the following definition to the source files of your application to use the flag:
///
/// #define I_CHILDRENAUTO (-2)
///
///
///
///
///
public int cChildren;
/// A value to associate with the item.
public IntPtr lParam;
/// The i integral
public int iIntegral;
/// The u state ex
public TreeViewItemStatesEx uStateEx;
/// The HWND
public HWND hwnd;
/// The i expanded image
public int iExpandedImage;
/// The i reserved
public int iReserved;
/// Gets or sets a value indicating whether this is bold.
/// true if bold; otherwise, false.
public bool Bold
{
get => GetState(TreeViewItemStates.TVIS_BOLD); set => SetState(TreeViewItemStates.TVIS_BOLD, value);
}
/// Gets or sets a value indicating whether this is expanded.
/// true if expanded; otherwise, false.
public bool Expanded
{
get => GetState(TreeViewItemStates.TVIS_EXPANDED); set => SetState(TreeViewItemStates.TVIS_EXPANDED, value);
}
/// Gets or sets a value indicating whether child items have been expanded at least once.
/// true if child items have been expanded at least once; otherwise, false.
public bool ExpandedOnce
{
get => GetState(TreeViewItemStates.TVIS_EXPANDEDONCE); set => SetState(TreeViewItemStates.TVIS_EXPANDEDONCE, value);
}
/// Gets or sets a value indicating whether item is partially expanded.
/// true if partially expanded; otherwise, false.
public bool ExpandedPartial
{
get => GetState(TreeViewItemStates.TVIS_EXPANDPARTIAL); set => SetState(TreeViewItemStates.TVIS_EXPANDPARTIAL, value);
}
/// Gets or sets the index of the overlay image.
/// The index of the overlay image.
/// OverlayImageIndex - Overlay image index must be between 0 and 15
public uint OverlayImageIndex
{
get => (state & 0x00000F00) >> 8; set
{
if (value > 15)
throw new ArgumentOutOfRangeException(nameof(OverlayImageIndex), "Overlay image index must be between 0 and 15");
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= TreeViewItemStates.TVIS_OVERLAYMASK;
state = (value << 8) | (state & 0xFFFFF0FF);
}
}
/// Gets or sets a value indicating whether this is selected.
/// true if selected; otherwise, false.
public bool Selected
{
get => GetState(TreeViewItemStates.TVIS_SELECTED); set => SetState(TreeViewItemStates.TVIS_SELECTED, value);
}
/// Gets or sets a value indicating whether item is selected as part of a cut-and-paste operation.
/// true if item is selected as part of a cut-and-paste operation; otherwise, false.
public bool SelectedForCut
{
get => GetState(TreeViewItemStates.TVIS_CUT); set => SetState(TreeViewItemStates.TVIS_CUT, value);
}
/// Gets or sets a value indicating whether item is selected as a drag-and-drop target.
/// true if item is selected as a drag-and-drop target; otherwise, false.
public bool SelectedForDragDrop
{
get => GetState(TreeViewItemStates.TVIS_DROPHILITED);
set => SetState(TreeViewItemStates.TVIS_DROPHILITED, value);
}
/// Gets the state.
/// The state.
public TreeViewItemStates State => (TreeViewItemStates)(state & 0x000000FF);
/// Gets or sets the index of the state image.
/// The index of the state image.
/// StateImageIndex - State image index must be between 0 and 15
public uint StateImageIndex
{
get => (state & 0x0000F000) >> 12; set
{
if (value > 15)
throw new ArgumentOutOfRangeException(nameof(StateImageIndex), "State image index must be between 0 and 15");
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= TreeViewItemStates.TVIS_STATEIMAGEMASK;
state = (value << 12) | (state & 0xFFFF0FFF);
}
}
/// Gets the text.
/// The text.
public string Text => (IntPtr)pszText == LPSTR_TEXTCALLBACK ? null : pszText.ToString();
/// Gets or sets a value indicating whether to use text callback.
/// true if to use text callback; otherwise, false.
public bool UseTextCallback
{
get => (IntPtr)pszText == LPSTR_TEXTCALLBACK;
set
{
if (value)
pszText.AssignConstant(-1);
mask |= TreeViewItemMask.TVIF_TEXT;
}
}
/// Gets a value on whether the specified state is set.
/// State of the item.
/// true if the specified state is set; otherwise, false.
public bool GetState(TreeViewItemStates itemState) => State.IsFlagSet(itemState);
/// Sets the state of the specified state.
/// State of the item.
/// if set to true set this state on.
public void SetState(TreeViewItemStates itemState, bool on = true)
{
mask |= TreeViewItemMask.TVIF_STATE;
stateMask |= itemState;
var tempState = State;
EnumExtensions.SetFlags(ref tempState, itemState, on);
state = (uint)tempState | (state & 0xFFFFFF00);
}
/// Sets the text.
/// The managed string PTR.
/// Length of the string.
public void SetText(IntPtr managedStringPtr, int stringLen)
{
pszText.Assign(managedStringPtr);
cchTextMax = stringLen;
mask |= TreeViewItemMask.TVIF_TEXT;
}
/// Returns a that represents this instance.
/// A that represents this instance.
public override string ToString() => $"TVITEM: pszText={Text}; iImage={iImage}; iSelectedImage={iSelectedImage}; state={state}; iExpandedImage={iExpandedImage}; iIntegral={iIntegral}; cChildren={cChildren}";
}
///
/// Contains information used to sort child items in a tree-view control. This structure is used with the TVM_SORTCHILDRENCB message.
/// This structure is identical to the TV_SORTCB structure, but it has been renamed to follow current naming conventions.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773462")]
[StructLayout(LayoutKind.Sequential)]
public struct TVSORTCB
{
/// Handle to the parent item.
public HTREEITEM hParent;
///
/// Address of an application-defined callback function, which is called during a sort operation each time the relative order of
/// two list items needs to be compared.
///
public PFNTVCOMPARE lpfnCompare;
///
/// Application-defined value that gets passed as the lParamSort argument in the callback function specified in lpfnCompare.
///
public IntPtr lParam;
}
///
/// Contains information for identifying the "hit zone" for a specified part of a tree item. The structure is used with the
/// TVM_GETITEMPARTRECT message and the TreeView_GetItemPartRect macro.
///
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb773442")]
[StructLayout(LayoutKind.Sequential)]
public sealed class TVGETITEMPARTRECTINFO : IDisposable
{
/// Handle to the parent item.
public HTREEITEM hti;
///
/// Pointer to a RECT structure to receive the coordinates of the bounding rectangle. The sender of the message (the caller) is
/// responsible for allocating this structure.
///
public IntPtr prc;
/// ID of the item part. This value must be TVGIPR_BUTTON (0x0001).
public TVITEMPART partID;
/// Initializes a new instance of the class.
/// The h tree node.
public TVGETITEMPARTRECTINFO(HTREEITEM hTreeNode)
{
hti = hTreeNode;
prc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(RECT)));
partID = TVITEMPART.TVGIPR_BUTTON;
}
/// Gets the bounds.
/// The bounds.
public RECT Bounds => prc.ToStructure();
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
void IDisposable.Dispose() => Marshal.FreeCoTaskMem(prc);
}
}
}