using System; using System.Drawing; 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 { #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member TVM_DELETEITEM = TV_FIRST + 1, TVM_EXPAND = TV_FIRST + 2, TVM_GETITEMRECT = TV_FIRST + 4, TVM_GETCOUNT = TV_FIRST + 5, TVM_GETINDENT = TV_FIRST + 6, TVM_SETINDENT = TV_FIRST + 7, TVM_GETIMAGELIST = TV_FIRST + 8, TVM_SETIMAGELIST = TV_FIRST + 9, TVM_GETNEXTITEM = TV_FIRST + 10, TVM_SELECTITEM = TV_FIRST + 11, TVM_GETEDITCONTROL = TV_FIRST + 15, TVM_GETVISIBLECOUNT = TV_FIRST + 16, TVM_HITTEST = TV_FIRST + 17, TVM_CREATEDRAGIMAGE = TV_FIRST + 18, TVM_SORTCHILDREN = TV_FIRST + 19, TVM_ENSUREVISIBLE = TV_FIRST + 20, TVM_SORTCHILDRENCB = TV_FIRST + 21, TVM_ENDEDITLABELNOW = TV_FIRST + 22, TVM_SETTOOLTIPS = TV_FIRST + 24, TVM_GETTOOLTIPS = TV_FIRST + 25, TVM_SETINSERTMARK = TV_FIRST + 26, TVM_SETUNICODEFORMAT = CommonControlMessage.CCM_SETUNICODEFORMAT, TVM_GETUNICODEFORMAT = CommonControlMessage.CCM_GETUNICODEFORMAT, TVM_SETITEMHEIGHT = TV_FIRST + 27, TVM_GETITEMHEIGHT = TV_FIRST + 28, TVM_SETBKCOLOR = TV_FIRST + 29, TVM_SETTEXTCOLOR = TV_FIRST + 30, TVM_GETBKCOLOR = TV_FIRST + 31, TVM_GETTEXTCOLOR = TV_FIRST + 32, TVM_SETSCROLLTIME = TV_FIRST + 33, TVM_GETSCROLLTIME = TV_FIRST + 34, TVM_SETINSERTMARKCOLOR = TV_FIRST + 37, TVM_GETINSERTMARKCOLOR = TV_FIRST + 38, TVM_SETBORDER = TV_FIRST + 35, TVM_GETITEMSTATE = TV_FIRST + 39, TVM_SETLINECOLOR = TV_FIRST + 40, TVM_GETLINECOLOR = TV_FIRST + 41, TVM_MAPACCIDTOHTREEITEM = TV_FIRST + 42, TVM_MAPHTREEITEMTOACCID = TV_FIRST + 43, TVM_SETEXTENDEDSTYLE = TV_FIRST + 44, TVM_GETEXTENDEDSTYLE = TV_FIRST + 45, TVM_INSERTITEM = TV_FIRST + 50, TVM_SETAUTOSCROLLINFO = TV_FIRST + 59, TVM_SETHOT = TV_FIRST + 58, TVM_GETITEM = TV_FIRST + 62, TVM_SETITEM = TV_FIRST + 63, TVM_GETISEARCHSTRING = TV_FIRST + 64, TVM_EDITLABEL = TV_FIRST + 65, TVM_GETSELECTEDCOUNT = TV_FIRST + 70, TVM_SHOWINFOTIP = TV_FIRST + 71, TVM_GETITEMPARTRECT = TV_FIRST + 72, #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } /// Tree View Notifications [PInvokeData("Commctrl.h", MSDNShortId = "ff486107")] public enum TreeViewNotification { #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member TVN_ASYNCDRAW = TVN_FIRST - 20, TVN_BEGINDRAG = TVN_FIRST - 56, TVN_BEGINLABELEDIT = TVN_FIRST - 59, TVN_BEGINRDRAG = TVN_FIRST - 57, TVN_DELETEITEM = TVN_FIRST - 58, TVN_ENDLABELEDIT = TVN_FIRST - 60, TVN_GETDISPINFO = TVN_FIRST - 52, TVN_GETINFOTIP = TVN_FIRST - 14, TVN_ITEMCHANGED = TVN_FIRST - 19, TVN_ITEMCHANGING = TVN_FIRST - 17, TVN_ITEMEXPANDED = TVN_FIRST - 55, TVN_ITEMEXPANDING = TVN_FIRST - 54, TVN_KEYDOWN = TVN_FIRST - 12, TVN_SELCHANGED = TVN_FIRST - 51, TVN_SELCHANGING = TVN_FIRST - 50, TVN_SETDISPINFO = TVN_FIRST - 53, TVN_SINGLEEXPAND = TVN_FIRST - 15, #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } /// 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 Rectangle Bounds => prc.ToStructure(); /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() => Marshal.FreeCoTaskMem(prc); } } }