using System; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Security.Permissions; using Vanara.Extensions; using Vanara.InteropServices; using static Vanara.PInvoke.User32; namespace Vanara.PInvoke { public static partial class ComCtl32 { /// /// Specifies that the size of the column array and the array itself (puColumns) are obtained by sending a LVN_GETDISPINFO notification. /// public const int I_COLUMNSCALLBACK = -1; /// The listview control sends the parent an LVN_GETDISPINFO notification code to retrieve the index of the group. public const int I_GROUPIDCALLBACK = -1; /// The item does not belong to a group. public const int I_GROUPIDNONE = -2; private const uint LVM_FIRST = 0x1000; private const int LVN_FIRST = -0x100; /// Values that specify alignment for LVM_ARRANGE. [PInvokeData("Commctrl.h")] public enum ListViewArrange { /// Aligns items according to the list-view control's current alignment styles (the default value). LVA_DEFAULT = 0x0000, /// Not implemented. Apply the LVS_ALIGNLEFT style instead. LVA_ALIGNLEFT = 0x0001, /// Not implemented. Apply the LVS_ALIGNTOP style instead. LVA_ALIGNTOP = 0x0002, /// Snaps all icons to the nearest grid position. LVA_SNAPTOGRID = 0x0005, } /// Flags for the member. [PInvokeData("Commctrl.h", MSDNShortId = "bb774742")] [Flags] public enum ListViewBkImageFlag : uint { /// The list-view control has no background image. LVBKIF_SOURCE_NONE = 0X00000000, /// /// A background bitmap is supplied via the hbm member of LVBKIMAGE. If the message LVM_SETBKIMAGE succeeds, then the list-view /// takes ownership of the bitmap. /// LVBKIF_SOURCE_HBITMAP = 0X00000001, /// The pszImage member contains the URL of the background image. LVBKIF_SOURCE_URL = 0X00000002, /// You can use the LVBKIF_SOURCE_MASK value to mask off all but the source flags. LVBKIF_SOURCE_MASK = 0X00000003, /// The background image is displayed normally. LVBKIF_STYLE_NORMAL = 0X00000000, /// The background image will be tiled to fill the entire background of the control. LVBKIF_STYLE_TILE = 0X00000010, /// You can use the LVBKIF_STYLE_MASK value to mask off all but the style flags. LVBKIF_STYLE_MASK = 0X00000010, /// /// Specify the coordinates of the first tile. This flag is valid only if the LVBKIF_STYLE_TILE flag is also specified. If this /// flag is not specified, the first tile begins at the upper-left corner of the client area. If you use ComCtl32.dll Version /// 6.0 the xOffsetPercent and yOffsetPercent fields contain pixels, not percentage values, to specify the coordinates of the /// first tile. Comctl32.dll version 6 is not redistributable but it is included in Windows or later. Also, you must specify /// Comctl32.dll version 6 in a manifest. For more information on manifests, see Enabling Visual Styles. /// LVBKIF_FLAG_TILEOFFSET = 0X00000100, /// /// A watermark background bitmap is supplied via the hbm member of LVBKIMAGE. If the LVM_SETBKIMAGE message succeeds, then the /// list-view control takes ownership of the bitmap. /// LVBKIF_TYPE_WATERMARK = 0X10000000, /// /// Valid only when LVBKIF_TYPE_WATERMARK is also specified. This flag indicates the bitmap provided via LVBKIF_TYPE_WATERMARK /// contains a valid alpha channel. /// LVBKIF_FLAG_ALPHABLEND = 0X20000000, } /// Mask flags used by . [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewColumMask { /// The fmt member is valid. LVCF_FMT = 0X0001, /// The cx member is valid. LVCF_WIDTH = 0X0002, /// The pszText member is valid. LVCF_TEXT = 0X0004, /// The iSubItem member is valid. LVCF_SUBITEM = 0X0008, /// Version 4.70. The iImage member is valid. LVCF_IMAGE = 0X0010, /// Version 4.70. The iOrder member is valid LVCF_ORDER = 0X0020, /// Version 6.00 and Windows Vista.The cxMin member is valid. LVCF_MINWIDTH = 0X0040, /// Version 6.00 and Windows Vista.The cxDefault member is valid. LVCF_DEFAULTWIDTH = 0X0080, /// Version 6.00 and Windows Vista.The cxIdeal member is valid LVCF_IDEALWIDTH = 0X0100, } /// /// Alignment of the column header and the subitem text in the column. The alignment of the leftmost column is always LVCFMT_LEFT; /// it cannot be changed. This member can be a combination of the following values. Note that not all combinations are valid. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774743")] [Flags] public enum ListViewColumnFormat { /// Text is left-aligned. LVCFMT_LEFT = 0X0000, /// Text is right-aligned. LVCFMT_RIGHT = 0X0001, /// Text is centered. LVCFMT_CENTER = 0X0002, /// /// A bitmask used to select those bits of fmt that control field justification. To check the format of a column, use a logical /// "and" to combine LCFMT_JUSTIFYMASK with fmt. You can then use a switch statement to determine whether the LVCFMT_LEFT, /// LVCFMT_RIGHT, or LVCFMT_CENTER bits are set. /// LVCFMT_JUSTIFYMASK = 0X0003, /// Version 4.70. The item displays an image from an image list. LVCFMT_IMAGE = 0X0800, /// /// Version 4.70. The bitmap appears to the right of text. This does not affect an image from an image list assigned to the /// header item. /// LVCFMT_BITMAP_ON_RIGHT = 0X1000, /// Version 4.70. The header item contains an image in the image list. LVCFMT_COL_HAS_IMAGES = 0X8000, /// Version 6.00 and Windows Vista. Can't resize the column; same as HDF_FIXEDWIDTH. LVCFMT_FIXED_WIDTH = 0X00100, /// Version 6.00 and Windows Vista. If not set, CCM_DPISCALE will govern scaling up fixed width. LVCFMT_NO_DPI_SCALE = 0X40000, /// Version 6.00 and Windows Vista. Width will augment with the row height. LVCFMT_FIXED_RATIO = 0X80000, /// Forces the column to wrap to the top of the next list of columns. LVCFMT_LINE_BREAK = 0X100000, /// Fills the remainder of the tile area. Might have a title. LVCFMT_FILL = 0X200000, /// Allows the column to wrap within the remaining space in its list of columns. LVCFMT_WRAP = 0X400000, /// Removes the title from the subitem. LVCFMT_NO_TITLE = 0X800000, /// Equivalent to a combination of LVCFMT_LINE_BREAK and LVCFMT_FILL. LVCFMT_TILE_PLACEMENTMASK = LVCFMT_LINE_BREAK | LVCFMT_FILL, /// /// Version 6.00 and Windows Vista. Column is a split button (same as HDF_SPLITBUTTON). The header of the column displays a /// split button (same as HDF_SPLITBUTTON). /// LVCFMT_SPLITBUTTON = 0X1000000, } /// Flags used in the member. [PInvokeData("Commctrl.h", MSDNShortId = "bb774745")] [Flags] public enum ListViewFindInfoFlag { /// Searches for a match between this structure's lParam member and the lParam member of an item's LVITEM structure. LVFI_PARAM = 0X0001, /// /// Searches based on the item text. Unless additional values are specified, the item text of the matching item must exactly /// match the string pointed to by the psz member. However, the search is case-insensitive. /// LVFI_STRING = 0X0002, /// Windows Vista and later. Equivalent to LVFI_PARTIAL. LVFI_SUBSTRING = 0X0004, /// /// Checks to see if the item text begins with the string pointed to by the psz member. This value implies use of LVFI_STRING. /// LVFI_PARTIAL = 0X0008, /// /// Continues the search at the beginning if no match is found. If this flag is used by itself, it is assumed that a string /// search is wanted. /// LVFI_WRAP = 0X0020, /// /// Finds the item nearest to the position specified in the pt member, in the direction specified by the vkDirection member. /// This flag is supported only by large icon and small icon modes. If LVFI_NEARESTXY is specified, all other flags are ignored. /// LVFI_NEARESTXY = 0X0040, } /// /// Indicates the alignment of the header or footer text for the group. It can have one or more of the following values. Use one of /// the header flags. Footer flags are optional. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewGroupAlignment { /// Header text is aligned at the left of the window. LVGA_HEADER_LEFT = 0x00000001, /// Header text is centered horizontally in the window. LVGA_HEADER_CENTER = 0x00000002, /// Header text is aligned at the right of the window. LVGA_HEADER_RIGHT = 0x00000004, // Don't forget to validate exclusivity /// Footer text is aligned at the left of the window. LVGA_FOOTER_LEFT = 0x00000008, /// Footer text is centered horizontally in the window. LVGA_FOOTER_CENTER = 0x00000010, /// Footer text is aligned at the right of the window. LVGA_FOOTER_RIGHT = 0x00000020, // Don't forget to validate exclusivity } /// Used to set and retrieve groups. [PInvokeData("Commctrl.h", MSDNShortId = "bb774769")] [Flags] public enum ListViewGroupMask : uint { /// No other items are valid. LVGF_NONE = 0x00000000, /// pszHeader and cchHeader members are valid. LVGF_HEADER = 0x00000001, /// pszFooter and cchFooter members are valid. LVGF_FOOTER = 0x00000002, /// state and stateMask members are valid. LVGF_STATE = 0x00000004, /// uAlign member is valid. LVGF_ALIGN = 0x00000008, /// iGroupId member is valid. LVGF_GROUPID = 0x00000010, /// Version 6.00 and later. The pszSubtitle member is valid. LVGF_SUBTITLE = 0x00000100, /// Version 6.00 and later. The pszTask member is valid. LVGF_TASK = 0x00000200, /// Version 6.00 and later. The pszDescriptionTop member is valid. LVGF_DESCRIPTIONTOP = 0x00000400, /// Version 6.00 and later. The pszDescriptionBottom member is valid. LVGF_DESCRIPTIONBOTTOM = 0x00000800, /// Version 6.00 and later. The iTitleImage member is valid. LVGF_TITLEIMAGE = 0x00001000, /// Version 6.00 and later. The iExtendedImage member is valid. LVGF_EXTENDEDIMAGE = 0x00002000, /// Version 6.00 and later. The cItems member is valid. LVGF_ITEMS = 0x00004000, /// Version 6.00 and later. The pszSubsetTitle member is valid. LVGF_SUBSET = 0x00008000, /// Version 6.00 and later. The cchSubsetTitle member is valid. LVGF_SUBSETITEMS = 0x00010000, } /// Flags that specify which members contain or are to receive valid data. [PInvokeData("Commctrl.h", MSDNShortId = "bb774752")] [Flags] public enum ListViewGroupMetricsMask { /// No members are valid. LVGMF_NONE = 0x00000000, /// The Left, Top, Right, and Bottom members are valid. LVGMF_BORDERSIZE = 0x00000001, /// Not implemented. LVGMF_BORDERCOLOR = 0x00000002, /// Not implemented. LVGMF_TEXTCOLOR = 0x00000004, } /// Value used in LVM_GETGROUPRECT lparam value to specify coordinates of the rectangle to get. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] public enum ListViewGroupRect { /// Coordinates of the entire expanded group. LVGGR_GROUP = 0, /// Coordinates of the header only (collapsed group). LVGGR_HEADER = 1, /// Coordinates of the label only. LVGGR_LABEL = 2, /// /// Coordinates of the subset link only (markup subset). A list-view control can limit the number of visible items displayed in /// each group. A link is presented to the user to allow the user to expand the group. This flag will return the bounding /// rectangle of the subset link if the group is a subset (group state of LVGS_SUBSETED, see structure LVGROUP, member state). /// This flag is provided so that accessibility applications can located the link. /// LVGGR_SUBSETLINK = 3, } /// [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewGroupState : uint { /// Groups are expanded, the group name is displayed, and all items in the group are displayed. LVGS_NORMAL = 0x00000000, /// The group is collapsed. LVGS_COLLAPSED = 0x00000001, /// The group is hidden. LVGS_HIDDEN = 0x00000002, /// Version 6.00 and later. The group does not display a header. LVGS_NOHEADER = 0x00000004, /// Version 6.00 and later. The group can be collapsed. LVGS_COLLAPSIBLE = 0x00000008, /// Version 6.00 and later. The group has keyboard focus. LVGS_FOCUSED = 0x00000010, /// Version 6.00 and later. The group is selected. LVGS_SELECTED = 0x00000020, /// Version 6.00 and later. The group displays only a portion of its items. LVGS_SUBSETED = 0x00000040, /// Version 6.00 and later. The subset link of the group has keyboard focus. LVGS_SUBSETLINKFOCUSED = 0x00000080, } /// The results of a hit test. This member can be one or more of the following values: [PInvokeData("Commctrl.h", MSDNShortId = "bb774754")] [Flags] public enum ListViewHitTestFlag : uint { /// The position is inside the list-view control's client window, but it is not over a list item. LVHT_NOWHERE = 0X00000001, /// The position is over a list-view item's icon. LVHT_ONITEMICON = 0X00000002, /// The position is over a list-view item's text. LVHT_ONITEMLABEL = 0X00000004, /// The position is over the state image of a list-view item. LVHT_ONITEMSTATEICON = 0X00000008, /// The position is over a list-view item. LVHT_ONITEM = LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON, /// The position is above the control's client area. LVHT_ABOVE = 0X00000008, /// The position is below the control's client area. LVHT_BELOW = 0X00000010, /// The position is to the right of the list-view control's client area. LVHT_TORIGHT = 0X00000020, /// The position is to the left of the list-view control's client area. LVHT_TOLEFT = 0X00000040, /// Windows Vista. The point is within the group header. LVHT_EX_GROUP_HEADER = 0X10000000, /// Windows Vista. The point is within the group footer. LVHT_EX_GROUP_FOOTER = 0X20000000, /// Windows Vista. The point is within the collapse/expand button of the group. LVHT_EX_GROUP_COLLAPSE = 0X40000000, /// Windows Vista. The point is within the area of the group where items are displayed. LVHT_EX_GROUP_BACKGROUND = 0X80000000, /// Windows Vista. The point is within the state icon of the group. LVHT_EX_GROUP_STATEICON = 0X01000000, /// Windows Vista. The point is within the subset link of the group. LVHT_EX_GROUP_SUBSETLINK = 0X02000000, /// /// Windows Vista. LVHT_EX_GROUP_BACKGROUND | LVHT_EX_GROUP_COLLAPSE | LVHT_EX_GROUP_FOOTER | LVHT_EX_GROUP_HEADER | /// LVHT_EX_GROUP_STATEICON | LVHT_EX_GROUP_SUBSETLINK. /// LVHT_EX_GROUP = LVHT_EX_GROUP_BACKGROUND | LVHT_EX_GROUP_COLLAPSE | LVHT_EX_GROUP_FOOTER | LVHT_EX_GROUP_HEADER | LVHT_EX_GROUP_STATEICON | LVHT_EX_GROUP_SUBSETLINK, /// Windows Vista. The point is within the icon or text content of the item and not on the background. LVHT_EX_ONCONTENTS = 0X04000000, /// Windows Vista. The point is within the footer of the list-view control. LVHT_EX_FOOTER = 0X08000000, } /// Type of image list. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] public enum ListViewImageList { /// Image list with large icons. LVSIL_NORMAL, /// Image list with small icons. LVSIL_SMALL, /// Image list with state images. LVSIL_STATE, /// Image list for group header. LVSIL_GROUPHEADER } /// Flag that specifies where the insertion point should appear. [PInvokeData("Commctrl.h", MSDNShortId = "bb774758")] public enum ListViewInsertMarkFlag { /// The insertion point appears before the item LVIM_BEFORE, /// The insertion point appears after the item LVIM_AFTER } /// /// Set of flags that specify which members of the structure contain data to be set or which members are being /// requested. This member can have one or more of the following flags set: /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774760")] [Flags] public enum ListViewItemMask : uint { /// The pszText member is valid or must be set. LVIF_TEXT = 0x00000001, /// The iImage member is valid or must be set. LVIF_IMAGE = 0x00000002, /// The lParam member is valid or must be set. LVIF_PARAM = 0x00000004, /// The state member is valid or must be set. LVIF_STATE = 0x00000008, /// The iIndent member is valid or must be set. LVIF_INDENT = 0x00000010, /// /// The control will not generate LVN_GETDISPINFO to retrieve text information if it receives an LVM_GETITEM message. Instead, /// the pszText member will contain LPSTR_TEXTCALLBACK. /// LVIF_NORECOMPUTE = 0x00000800, /// /// The iGroupId member is valid or must be set. If this flag is not set when an LVM_INSERTITEM message is sent, the value of /// iGroupId is assumed to be I_GROUPIDCALLBACK. /// LVIF_GROUPID = 0x00000100, /// The cColumns member is valid or must be set. LVIF_COLUMNS = 0x00000200, /// /// Windows Vista and later. The piColFmt member is valid or must be set. If this flag is used, the cColumns member is valid or /// must be set. /// LVIF_COLFMT = 0x00010000, /// /// The operating system should store the requested list item information and not ask for it again. This flag is used only with /// the LVN_GETDISPINFO notification code. /// LVIF_DISETITEM = 0x1000, /// Complete mask. LVIF_ALL = 0x0001FFFF } /// Used by LVM_GETITEMINDEXRECT. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] public enum ListViewItemRect { /// Returns the bounding rectangle of the entire subitem, including the icon and label. LVIR_BOUNDS, /// Returns the bounding rectangle of the icon or small icon of the subitem. LVIR_ICON, /// Returns the bounding rectangle of the subitem text. LVIR_LABEL, /// Returns the union of the LVIR_ICON and LVIR_LABEL rectangles, but excludes columns in report view. LVIR_SELECTBOUNDS } /// /// An item's state value consists of the item's state, an optional overlay mask index, and an optional state image mask index. An /// item's state determines its appearance and functionality. The state can be zero or one or more of the following values: /// [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewItemState : uint { /// No flags set. LVIS_NONE = 0x0000, /// /// The item has the focus, so it is surrounded by a standard focus rectangle. Although more than one item may be selected, only /// one item can have the focus. /// LVIS_FOCUSED = 0x0001, /// /// The item is selected. The appearance of a selected item depends on whether it has the focus and also on the system colors /// used for selection. /// LVIS_SELECTED = 0x0002, /// The item is marked for a cut-and-paste operation. LVIS_CUT = 0x0004, /// The item is highlighted as a drag-and-drop target. LVIS_DROPHILITED = 0x0008, /// Undocumented. LVIS_GLOW = 0x0010, // /// // Not currently supported. // Activating = 0x0020, /// The item's overlay image index is retrieved by a mask. LVIS_OVERLAYMASK = 0x0F00, /// The item's state image index is retrieved by a mask. LVIS_STATEIMAGEMASK = 0xF000, /// All flags. LVIS_ALL = 0xFFFFFFFF } /// LVM_ Messages for SendMessage [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] public enum ListViewMessage : uint { #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member LVM_SETUNICODEFORMAT = 0X2005, // CCM_SETUNICODEFORMAT, LVM_GETUNICODEFORMAT = 0X2006, // CCM_GETUNICODEFORMAT, LVM_GETBKCOLOR = LVM_FIRST + 0, LVM_SETBKCOLOR = LVM_FIRST + 1, LVM_GETIMAGELIST = LVM_FIRST + 2, LVM_SETIMAGELIST = LVM_FIRST + 3, LVM_GETITEMCOUNT = LVM_FIRST + 4, LVM_GETITEM = LVM_FIRST + 75, LVM_SETITEM = LVM_FIRST + 76, LVM_INSERTITEM = LVM_FIRST + 77, LVM_DELETEITEM = LVM_FIRST + 8, LVM_DELETEALLITEMS = LVM_FIRST + 9, LVM_GETCALLBACKMASK = LVM_FIRST + 10, LVM_SETCALLBACKMASK = LVM_FIRST + 11, LVM_GETNEXTITEM = LVM_FIRST + 12, LVM_FINDITEM = LVM_FIRST + 83, LVM_GETITEMRECT = LVM_FIRST + 14, LVM_SETITEMPOSITION = LVM_FIRST + 15, LVM_GETITEMPOSITION = LVM_FIRST + 16, LVM_GETSTRINGWIDTH = LVM_FIRST + 87, LVM_HITTEST = LVM_FIRST + 18, LVM_ENSUREVISIBLE = LVM_FIRST + 19, LVM_SCROLL = LVM_FIRST + 20, LVM_REDRAWITEMS = LVM_FIRST + 21, LVM_ARRANGE = LVM_FIRST + 22, LVM_EDITLABEL = LVM_FIRST + 118, LVM_GETEDITCONTROL = LVM_FIRST + 24, LVM_GETCOLUMN = LVM_FIRST + 95, LVM_SETCOLUMN = LVM_FIRST + 96, LVM_INSERTCOLUMN = LVM_FIRST + 97, LVM_DELETECOLUMN = LVM_FIRST + 28, LVM_GETCOLUMNWIDTH = LVM_FIRST + 29, LVM_SETCOLUMNWIDTH = LVM_FIRST + 30, LVM_GETHEADER = LVM_FIRST + 31, LVM_CREATEDRAGIMAGE = LVM_FIRST + 33, LVM_GETVIEWRECT = LVM_FIRST + 34, LVM_GETTEXTCOLOR = LVM_FIRST + 35, LVM_SETTEXTCOLOR = LVM_FIRST + 36, LVM_GETTEXTBKCOLOR = LVM_FIRST + 37, LVM_SETTEXTBKCOLOR = LVM_FIRST + 38, LVM_GETTOPINDEX = LVM_FIRST + 39, LVM_GETCOUNTPERPAGE = LVM_FIRST + 40, LVM_GETORIGIN = LVM_FIRST + 41, LVM_UPDATE = LVM_FIRST + 42, LVM_SETITEMSTATE = LVM_FIRST + 43, LVM_GETITEMSTATE = LVM_FIRST + 44, LVM_GETITEMTEXT = LVM_FIRST + 115, LVM_SETITEMTEXT = LVM_FIRST + 116, LVM_SETITEMCOUNT = LVM_FIRST + 47, LVM_SORTITEMS = LVM_FIRST + 48, LVM_SETITEMPOSITION32 = LVM_FIRST + 49, LVM_GETSELECTEDCOUNT = LVM_FIRST + 50, LVM_GETITEMSPACING = LVM_FIRST + 51, LVM_GETISEARCHSTRING = LVM_FIRST + 117, LVM_SETICONSPACING = LVM_FIRST + 53, LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54, // OPTIONAL WPARAM == MASK LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55, LVM_GETSUBITEMRECT = LVM_FIRST + 56, LVM_SUBITEMHITTEST = LVM_FIRST + 57, LVM_SETCOLUMNORDERARRAY = LVM_FIRST + 58, LVM_GETCOLUMNORDERARRAY = LVM_FIRST + 59, LVM_SETHOTITEM = LVM_FIRST + 60, LVM_GETHOTITEM = LVM_FIRST + 61, LVM_SETHOTCURSOR = LVM_FIRST + 62, LVM_GETHOTCURSOR = LVM_FIRST + 63, LVM_APPROXIMATEVIEWRECT = LVM_FIRST + 64, LVM_SETWORKAREAS = LVM_FIRST + 65, LVM_GETWORKAREAS = LVM_FIRST + 70, LVM_GETNUMBEROFWORKAREAS = LVM_FIRST + 73, LVM_GETSELECTIONMARK = LVM_FIRST + 66, LVM_SETSELECTIONMARK = LVM_FIRST + 67, LVM_SETHOVERTIME = LVM_FIRST + 71, LVM_GETHOVERTIME = LVM_FIRST + 72, LVM_SETTOOLTIPS = LVM_FIRST + 74, LVM_GETTOOLTIPS = LVM_FIRST + 78, LVM_SORTITEMSEX = LVM_FIRST + 81, LVM_SETBKIMAGE = LVM_FIRST + 138, LVM_GETBKIMAGE = LVM_FIRST + 139, LVM_SETSELECTEDCOLUMN = LVM_FIRST + 140, LVM_SETVIEW = LVM_FIRST + 142, LVM_GETVIEW = LVM_FIRST + 143, LVM_INSERTGROUP = LVM_FIRST + 145, LVM_SETGROUPINFO = LVM_FIRST + 147, LVM_GETGROUPINFO = LVM_FIRST + 149, LVM_REMOVEGROUP = LVM_FIRST + 150, LVM_MOVEGROUP = LVM_FIRST + 151, LVM_GETGROUPCOUNT = LVM_FIRST + 152, LVM_GETGROUPINFOBYINDEX = LVM_FIRST + 153, LVM_MOVEITEMTOGROUP = LVM_FIRST + 154, LVM_GETGROUPRECT = LVM_FIRST + 98, LVM_SETGROUPMETRICS = LVM_FIRST + 155, LVM_GETGROUPMETRICS = LVM_FIRST + 156, LVM_ENABLEGROUPVIEW = LVM_FIRST + 157, LVM_SORTGROUPS = LVM_FIRST + 158, LVM_INSERTGROUPSORTED = LVM_FIRST + 159, LVM_REMOVEALLGROUPS = LVM_FIRST + 160, LVM_HASGROUP = LVM_FIRST + 161, LVM_GETGROUPSTATE = LVM_FIRST + 92, LVM_GETFOCUSEDGROUP = LVM_FIRST + 93, LVM_SETTILEVIEWINFO = LVM_FIRST + 162, LVM_GETTILEVIEWINFO = LVM_FIRST + 163, LVM_SETTILEINFO = LVM_FIRST + 164, LVM_GETTILEINFO = LVM_FIRST + 165, LVM_SETINSERTMARK = LVM_FIRST + 166, LVM_GETINSERTMARK = LVM_FIRST + 167, LVM_INSERTMARKHITTEST = LVM_FIRST + 168, LVM_GETINSERTMARKRECT = LVM_FIRST + 169, LVM_SETINSERTMARKCOLOR = LVM_FIRST + 170, LVM_GETINSERTMARKCOLOR = LVM_FIRST + 171, LVM_GETSELECTEDCOLUMN = LVM_FIRST + 174, LVM_ISGROUPVIEWENABLED = LVM_FIRST + 175, LVM_GETOUTLINECOLOR = LVM_FIRST + 176, LVM_SETOUTLINECOLOR = LVM_FIRST + 177, LVM_CANCELEDITLABEL = LVM_FIRST + 179, LVM_MAPINDEXTODD = LVM_FIRST + 180, LVM_MAPIDTOINDEX = LVM_FIRST + 181, LVM_ISITEMVISIBLE = LVM_FIRST + 182, LVM_GETACCVERSION = LVM_FIRST + 193, LVM_GETEMPTYTEXT = LVM_FIRST + 204, LVM_GETFOOTERRECT = LVM_FIRST + 205, LVM_GETFOOTERINFO = LVM_FIRST + 206, LVM_GETFOOTERITEMRECT = LVM_FIRST + 207, LVM_GETFOOTERITEM = LVM_FIRST + 208, LVM_GETITEMINDEXRECT = LVM_FIRST + 209, LVM_SETITEMINDEXSTATE = LVM_FIRST + 210, LVM_GETNEXTITEMINDEX = LVM_FIRST + 211, LVM_SETPRESERVEALPHA = LVM_FIRST + 212, /*LVM_SetBkImage = SETBKIMAGEW, LVM_GetBkImage = GETBKIMAGEW,*/ #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } /// Specifies the relationship to the item listed in parameter wParam in LVM_GETNEXTITEMINDEX. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewNextItemFlag { /// Searches for a subsequent item by index, the default value. LVNI_ALL = 0X0000, /// The item has the LVIS_FOCUSED state flag set. LVNI_FOCUSED = 0X0001, /// The item has the LVIS_SELECTED state flag set. LVNI_SELECTED = 0X0002, /// The item has the LVIS_CUT state flag set. LVNI_CUT = 0X0004, /// The item has the LVIS_DROPHILITED state flag set LVNI_DROPHILITED = 0X0008, /// /// Windows Vista and later: A state flag mask with value as follows: LVNI_FOCUSED | LVNI_SELECTED | LVNI_CUT | LVNI_DROPHILITED. /// LVNI_STATEMASK = LVNI_FOCUSED | LVNI_SELECTED | LVNI_CUT | LVNI_DROPHILITED, /// Windows Vista and later: Search the visible order. LVNI_VISIBLEORDER = 0X0010, /// /// Windows Vista and later: Searches for an item that is ordered before the item specified in wParam. The LVNI_PREVIOUS flag is /// not directional (LVNI_ABOVE will find the item positioned above, while LVNI_PREVIOUS will find the item ordered before.) The /// LVNI_PREVIOUS flag basically reverses the logic of the search performed by the LVM_GETNEXTITEM or LVM_GETNEXTITEMINDEX messages. /// LVNI_PREVIOUS = 0X0020, /// Windows Vista and later: Search the visible items. LVNI_VISIBLEONLY = 0X0040, /// Windows Vista and later: Search the current group. LVNI_SAMEGROUPONLY = 0X0080, /// Searches for an item that is above the specified item. LVNI_ABOVE = 0X0100, /// Searches for an item that is below the specified item. LVNI_BELOW = 0X0200, /// Searches for an item to the left of the specified item. LVNI_TOLEFT = 0X0400, /// Searches for an item to the right of the specified item. LVNI_TORIGHT = 0X0800, /// /// Windows Vista and later: A directional flag mask with value as follows: LVNI_ABOVE | LVNI_BELOW | LVNI_TOLEFT | LVNI_TORIGHT. /// LVNI_DIRECTIONMASK = LVNI_ABOVE | LVNI_BELOW | LVNI_TOLEFT | LVNI_TORIGHT, } /// ListView notification identifiers. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] public enum ListViewNotification { #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member LVN_BEGINDRAG = (LVN_FIRST - 9), LVN_BEGINLABELEDIT = LVN_BEGINLABELEDITW, LVN_BEGINLABELEDITA = (LVN_FIRST - 5), LVN_BEGINLABELEDITW = (LVN_FIRST - 75), LVN_BEGINRDRAG = (LVN_FIRST - 11), LVN_BEGINSCROLL = (LVN_FIRST - 80), LVN_COLUMNCLICK = (LVN_FIRST - 8), LVN_COLUMNDROPDOWN = (LVN_FIRST - 64), LVN_COLUMNOVERFLOWCLICK = (LVN_FIRST - 66), LVN_DELETEALLITEMS = (LVN_FIRST - 4), LVN_DELETEITEM = (LVN_FIRST - 3), LVN_ENDLABELEDIT = LVN_ENDLABELEDITW, LVN_ENDLABELEDITA = (LVN_FIRST - 6), LVN_ENDLABELEDITW = (LVN_FIRST - 76), LVN_ENDSCROLL = (LVN_FIRST - 81), LVN_GETDISPINFO = LVN_GETDISPINFOW, LVN_GETDISPINFOA = (LVN_FIRST - 50), LVN_GETDISPINFOW = (LVN_FIRST - 77), LVN_GETEMPTYMARKUP = (LVN_FIRST - 87), LVN_GETINFOTIP = LVN_GETINFOTIPW, LVN_GETINFOTIPA = (LVN_FIRST - 57), LVN_GETINFOTIPW = (LVN_FIRST - 58), LVN_HOTTRACK = (LVN_FIRST - 21), LVN_INCREMENTALSEARCH = LVN_INCREMENTALSEARCHW, LVN_INCREMENTALSEARCHA = (LVN_FIRST - 62), LVN_INCREMENTALSEARCHW = (LVN_FIRST - 63), LVN_INSERTITEM = (LVN_FIRST - 2), LVN_ITEMACTIVATE = (LVN_FIRST - 14), LVN_ITEMCHANGED = (LVN_FIRST - 1), LVN_ITEMCHANGING = (LVN_FIRST - 0), LVN_KEYDOWN = (LVN_FIRST - 55), LVN_LINKCLICK = (LVN_FIRST - 84), LVN_MARQUEEBEGIN = (LVN_FIRST - 56), LVN_ODCACHEHINT = (LVN_FIRST - 13), LVN_ODFINDITEM = LVN_ODFINDITEMW, LVN_ODFINDITEMA = (LVN_FIRST - 52), LVN_ODFINDITEMW = (LVN_FIRST - 79), LVN_ODSTATECHANGED = (LVN_FIRST - 15), LVN_SETDISPINFO = LVN_SETDISPINFOW, LVN_SETDISPINFOA = (LVN_FIRST - 51), LVN_SETDISPINFOW = (LVN_FIRST - 78), #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } /// The following window styles are specific to list-view controls. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewStyle : uint { /// Items are left-aligned in icon and small icon view. LVS_ALIGNLEFT = 0x0800, /// The control's current alignment. LVS_ALIGNMASK = 0x0c00, /// Items are aligned with the top of the list-view control in icon and small icon view. LVS_ALIGNTOP = 0x0000, /// Icons are automatically kept arranged in icon and small icon view. LVS_AUTOARRANGE = 0x0100, /// Item text can be edited in place. The parent window must process the LVN_ENDLABELEDIT notification code. LVS_EDITLABELS = 0x0200, /// This style specifies icon view. LVS_ICON = 0x0000, /// This style specifies list view. LVS_LIST = 0x0003, /// Column headers are not displayed in report view. By default, columns have headers in report view. LVS_NOCOLUMNHEADER = 0x4000, /// Item text is displayed on a single line in icon view. By default, item text may wrap in icon view. LVS_NOLABELWRAP = 0x0080, /// /// Scrolling is disabled. All items must be within the client area. This style is not compatible with the LVS_LIST or /// LVS_REPORT styles. See Knowledge Base Article Q137520 for further discussion. /// LVS_NOSCROLL = 0x2000, /// /// Column headers do not work like buttons. This style can be used if clicking a column header in report view does not carry /// out an action, such as sorting. /// LVS_NOSORTHEADER = 0x8000, /// /// Version 4.70. This style specifies a virtual list-view control. For more information about this list control style, see /// About List-View Controls. /// LVS_OWNERDATA = 0x1000, /// /// The owner window can paint items in report view. The list-view control sends a WM_DRAWITEM message to paint each item; it /// does not send separate messages for each subitem. The iItemData member of the DRAWITEMSTRUCT structure contains the item /// data for the specified list-view item. /// LVS_OWNERDRAWFIXED = 0x0400, /// /// This style specifies report view. When using the LVS_REPORT style with a list-view control, the first column is always /// left-aligned. You cannot use LVCFMT_RIGHT to change this alignment. See LVCOLUMN for further information on column alignment. /// LVS_REPORT = 0x0001, /// /// The image list will not be deleted when the control is destroyed. This style enables the use of the same image lists with /// multiple list-view controls. /// LVS_SHAREIMAGELISTS = 0x0040, /// The selection, if any, is always shown, even if the control does not have the focus. LVS_SHOWSELALWAYS = 0x0008, /// Only one item at a time can be selected. By default, multiple items may be selected. LVS_SINGLESEL = 0x0004, /// This style specifies small icon view. LVS_SMALLICON = 0x0002, /// Item indexes are sorted based on item text in ascending order. LVS_SORTASCENDING = 0x0010, /// Item indexes are sorted based on item text in descending order. LVS_SORTDESCENDING = 0x0020, /// Determines the control's current window style. LVS_TYPEMASK = 0x0003, /// Determines the window styles that control item alignment and header appearance and behavior. LVS_TYPESTYLEMASK = 0xfc00, } /// /// Extended List-View Styles. Use the LVM_SETEXTENDEDLISTVIEWSTYLE message or one of the ListView_SetExtendedListViewStyle or /// ListView_SetExtendedListViewStyleEx macros to employ these extended list-view control styles. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [Flags] public enum ListViewStyleEx : uint { /// Windows Vista and later. Automatically arrange icons if no icon positions have been set (Similar to LVS_AUTOARRANGE). LVS_EX_AUTOAUTOARRANGE = 0X01000000, /// Windows Vista and later. Automatically select check boxes on single click. LVS_EX_AUTOCHECKSELECT = 0X08000000, /// Windows Vista and later. Automatically size listview columns. LVS_EX_AUTOSIZECOLUMNS = 0X10000000, /// Version 4.71 and later. Changes border color when an item is selected, instead of highlighting the item. LVS_EX_BORDERSELECT = 0X00008000, /// /// Version 4.70. Enables check boxes for items in a list-view control. When set to this style, the control creates and sets a /// state image list with two images using DrawFrameControl. 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. /// /// Version 6.00 and later Check boxes are visible and functional with all list view modes except the tile view mode introduced /// in ComCtl32.dll version 6. Clicking a checkbox in tile view mode only selects the item; the state does not change. /// /// /// You can obtain the state of the check box for a given item with ListView_GetCheckState. To set the check state, use /// ListView_SetCheckState. If this style is set, the list-view control automatically toggles the check state when the user /// clicks the check box or presses the space bar. /// /// LVS_EX_CHECKBOXES = 0X00000004, /// /// Indicates that an overflow button should be displayed in icon/tile view if there is not enough client width to display the /// complete set of header items. The list-view control sends the LVN_COLUMNOVERFLOWCLICK notification when the overflow button /// is clicked. This flag is only valid when LVS_EX_HEADERINALLVIEWS is also specified. /// LVS_EX_COLUMNOVERFLOW = 0X80000000, /// Windows Vista and later. Snap to minimum column width when the user resizes a column. LVS_EX_COLUMNSNAPPOINTS = 0X40000000, /// /// Version 6.00 and later. Paints via double-buffering, which reduces flicker. This extended style also enables alpha-blended /// marquee selection on systems where it is supported. /// LVS_EX_DOUBLEBUFFER = 0X00010000, /// /// Enables flat scroll bars in the list view. If you need more control over the appearance of the list view's scroll bars, you /// should manipulate the list view's scroll bars directly using the Flat Scroll Bar APIs. If the system metrics change, you are /// responsible for adjusting the scroll bar metrics with FlatSB_SetScrollProp. See Flat Scroll Bars for further details. /// LVS_EX_FLATSB = 0X00000100, /// /// When an item is selected, the item and all its subitems are highlighted. This style is available only in conjunction with /// the LVS_REPORT style. /// LVS_EX_FULLROWSELECT = 0X00000020, /// /// Displays gridlines around items and subitems. This style is available only in conjunction with the LVS_REPORT style. /// LVS_EX_GRIDLINES = 0X00000001, /// /// Enables drag-and-drop reordering of columns in a list-view control. This style is only available to list-view controls that /// use the LVS_REPORT style. /// LVS_EX_HEADERDRAGDROP = 0X00000010, /// Windows Vista and later. Show column headers in all view modes. LVS_EX_HEADERINALLVIEWS = 0X02000000, /// Version 6.00 and later. Hides the labels in icon and small icon view. LVS_EX_HIDELABELS = 0X00020000, /// /// When a list-view control uses the LVS_EX_INFOTIP style, the LVN_GETINFOTIP notification code is sent to the parent window /// before displaying an item's tooltip. /// LVS_EX_INFOTIP = 0X00000400, /// Windows Vista and later. Icons are lined up in columns that use up the whole view. LVS_EX_JUSTIFYCOLUMNS = 0X00200000, /// /// If a partially hidden label in any list view mode lacks tooltip text, the list-view control will unfold the label. If this /// style is not set, the list-view control will unfold partly hidden labels only for the large icon mode. /// LVS_EX_LABELTIP = 0X00004000, /// /// If the list-view control has the LVS_AUTOARRANGE style, the control will not autoarrange its icons until one or more work /// areas are defined (see LVM_SETWORKAREAS). To be effective, this style must be set before any work areas are defined and any /// items have been added to the control. /// LVS_EX_MULTIWORKAREAS = 0X00002000, /// /// The list-view control sends an LVN_ITEMACTIVATE notification code to the parent window when the user clicks an item. This /// style also enables hot tracking in the list-view control. Hot tracking means that when the cursor moves over an item, it is /// highlighted but not selected. See the Extended List-View Styles Remarks section for a discussion of item activation. /// LVS_EX_ONECLICKACTIVATE = 0X00000040, /// /// Version 4.71 through Version 5.80 only. Not supported on Windows Vista and later. Sets the list view window region to /// include only the item icons and text using SetWindowRgn. Any area that is not part of an item is excluded from the window /// region. This style is only available to list-view controls that use the LVS_ICON style. /// LVS_EX_REGIONAL = 0X00000200, /// /// Version 6.00 and later. In icon view, moves the state image of the control to the top right of the large icon rendering. In /// views other than icon view there is no change. When the user changes the state by using the space bar, all selected items /// cycle over, not the item with the focus. /// LVS_EX_SIMPLESELECT = 0X00100000, /// Version 6.00 and later. Not used. LVS_EX_SINGLEROW = 0X00040000, /// Version 6.00 and later. In icon view, icons automatically snap into a grid. LVS_EX_SNAPTOGRID = 0X00080000, /// /// Allows images to be displayed for subitems. This style is available only in conjunction with the LVS_REPORT style. /// LVS_EX_SUBITEMIMAGES = 0X00000002, /// /// Enables hot-track selection in a list-view control. Hot track selection means that an item is automatically selected when /// the cursor remains over the item for a certain period of time. The delay can be changed from the default system setting with /// a LVM_SETHOVERTIME message. This style applies to all styles of list-view control. You can check whether hot-track selection /// is enabled by calling SystemParametersInfo. /// LVS_EX_TRACKSELECT = 0X00000008, /// Windows Vista and later. Background is painted by the parent via WM_PRINTCLIENT. LVS_EX_TRANSPARENTBKGND = 0X00400000, /// Windows Vista and later. Enable shadow text on transparent backgrounds only. LVS_EX_TRANSPARENTSHADOWTEXT = 0X00800000, /// /// The list-view control sends an LVN_ITEMACTIVATE notification code to the parent window when the user double-clicks an item. /// This style also enables hot tracking in the list-view control. Hot tracking means that when the cursor moves over an item, /// it is highlighted but not selected. See the Extended List-View Styles Remarks section for a discussion of item activation. /// LVS_EX_TWOCLICKACTIVATE = 0X00000080, /// /// Causes those non-hot items that may be activated to be displayed with underlined text. This style requires that /// LVS_EX_TWOCLICKACTIVATE be set also. See the Extended List-View Styles Remarks section for a discussion of item activation. /// LVS_EX_UNDERLINECOLD = 0X00001000, /// /// Causes those hot items that may be activated to be displayed with underlined text. This style requires that /// LVS_EX_ONECLICKACTIVATE or LVS_EX_TWOCLICKACTIVATE also be set. See the Extended List-View Styles Remarks section for a /// discussion of item activation. /// LVS_EX_UNDERLINEHOT = 0X00000800, } /// Flags that determines how the tiles are sized in tile view. [PInvokeData("Commctrl.h", MSDNShortId = "bb774768")] [Flags] public enum ListViewTileViewFlag : uint { /// Size the tiles automatically. LVTVIF_AUTOSIZE = 0x00000000, /// Apply a fixed width to the tiles. LVTVIF_FIXEDWIDTH = 0x00000001, /// Apply a fixed height to the tiles. LVTVIF_FIXEDHEIGHT = 0x00000002, /// Apply a fixed height and width to the tiles. LVTVIF_FIXEDSIZE = 0x00000003, /// This flag is not supported and should not be used. LVTVIF_EXTENDED = 0x00000004, } /// Mask that determines which members of the LVTILEVIEWINFO structure are valid. [PInvokeData("Commctrl.h", MSDNShortId = "bb774768")] [Flags] public enum ListViewTileViewMask : uint { /// sizeTile is valid. LVTVIM_TILESIZE = 0x00000001, /// cLines is valid. LVTVIM_COLUMNS = 0x00000002, /// rcLabelMargin is valid. LVTVIM_LABELMARGIN = 0x00000004, } /// /// /// Gets the bounding rectangle for all or part of a subitem in the current view of a specified list-view control. Use this macro or /// send the LVM_GETITEMINDEXRECT message explicitly. /// /// /// /// Type: HWND /// A handle to the list-view control. /// /// /// Type: LVITEMINDEX* /// /// A pointer to a LVITEMINDEX structure for the parent item of the subitem. The caller is responsible for allocating this structure /// and setting its members. plvii must not be NULL. /// /// /// /// Type: LONG /// The index of the subitem. /// /// /// Type: LONG /// /// The portion of the list-view subitem for which to retrieve the bounding rectangle. This parameter must be one of the following values. /// /// /// /// Value /// Meaning /// /// /// LVIR_BOUNDS /// Returns the bounding rectangle of the entire subitem, including the icon and label. /// /// /// LVIR_ICON /// Returns the bounding rectangle of the icon or small icon of the subitem. /// /// /// LVIR_LABEL /// Returns the bounding rectangle of the subitem text. /// /// /// /// /// A Rectangle structure to receive the coordinates. /// /// Returns TRUE if successful, or FALSE otherwise. /// /// /// If iSubItem is zero, this macro returns the coordinates of the rectangle to the item pointed to by plvii. The value /// LVIR_SELECTBOUNDS for the parameter code is not supported. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/commctrl/nf-commctrl-listview_getitemindexrect [PInvokeData("commctrl.h", MSDNShortId = "listview_getitemindexrect")] public static bool ListView_GetItemIndexRect(HWND hwnd, in LVITEMINDEX plvii, int iSubItem, ListViewItemRect code, out Rectangle prc) { var rc = new PRECT((int)code, iSubItem, 0, 0); var lr = SendMessage(hwnd, ListViewMessage.LVM_GETITEMINDEXRECT, plvii, rc); prc = lr == IntPtr.Zero ? Rectangle.Empty : (Rectangle)rc; return lr != IntPtr.Zero; } /// /// Gets the index of the item in a particular list-view control that has the specified properties and relationship to another /// specific item. Use this macro or send the LVM_GETNEXTITEMINDEX message explicitly. /// /// /// Type: HWND /// A handle to the list-view control. /// /// /// Type: LVITEMINDEX* /// /// A pointer to the LVITEMINDEX structure with which the item begins the search, or -1 to find the first item that matches /// the specified flags. The calling process is responsible for allocating this structure and setting its members. /// /// /// /// Type: LPARAM /// The relationship to the item specified in parameter plvii. This can be one or a combination of the following values: /// /// /// /// Value /// Meaning /// /// /// Searches by index. /// /// /// /// LVNI_ALL /// Searches for a subsequent item by index, the default value. /// /// /// Searches by physical relationship to the index of the item where the search is to begin. /// /// /// /// LVNI_ABOVE /// Searches for an item that is above the specified item. /// /// /// LVNI_BELOW /// Searches for an item that is below the specified item. /// /// /// LVNI_TOLEFT /// Searches for an item to the left of the specified item. /// /// /// LVNI_PREVIOUS /// /// Windows Vista and later: Searches for the item that is previous to the specified item. The LVNI_PREVIOUS flag is not directional /// (LVNI_ABOVE will find the item positioned above, while LVNI_PREVIOUS will find the item ordered before.) The LVNI_PREVIOUS flag /// essentially reverses the logic of the search performed via the LVM_GETNEXTITEM or LVM_GETNEXTITEMINDEX messages. /// /// /// /// LVNI_TORIGHT /// Searches for an item to the right of the specified item. /// /// /// LVNI_DIRECTIONMASK /// Windows Vista and later: A directional flag mask with value as follows: LVNI_ABOVE | LVNI_BELOW | LVNI_TOLEFT | LVNI_TORIGHT. /// /// /// The state of the item to find can be specified with one or a combination of the following values: /// /// /// /// LVNI_CUT /// The item has the LVIS_CUT state flag set. /// /// /// LVNI_DROPHILITED /// The item has the LVIS_DROPHILITED state flag set /// /// /// LVNI_FOCUSED /// The item has the LVIS_FOCUSED state flag set. /// /// /// LVNI_SELECTED /// The item has the LVIS_SELECTED state flag set. /// /// /// LVNI_STATEMASK /// Windows Vista and later: A state flag mask with value as follows: LVNI_FOCUSED | LVNI_SELECTED | LVNI_CUT | LVNI_DROPHILITED. /// /// /// Searches by appearance of items or by group. /// /// /// /// LVNI_VISIBLEORDER /// Windows Vista and later: Search the visible order. /// /// /// LVNI_VISIBLEONLY /// Windows Vista and later: Search the visible items. /// /// /// LVNI_SAMEGROUPONLY /// Windows Vista and later: Search the current group. /// /// /// If an item does not have all of the specified state flags set, the search continues with the next item. /// /// /// /// /// /// Returns TRUE if successful, or FALSE otherwise. // BOOL ListView_GetNextItemIndex( [in] HWND hwnd, [in, out] LVITEMINDEX *plvii, LPARAM flags); https://msdn.microsoft.com/en-us/library/windows/desktop/bb774986(v=vs.85).aspx [PInvokeData("Commctrl.h", MSDNShortId = "bb774986")] public static bool ListView_GetNextItemIndex(HWND hwnd, in LVITEMINDEX plvii, ListViewNextItemFlag flags) => SendMessage(hwnd, (uint)ListViewMessage.LVM_GETNEXTITEMINDEX, (IntPtr)SafeCoTaskMemHandle.CreateFromStructure(plvii), (IntPtr)(int)flags) != IntPtr.Zero; /// /// Sets the state of a specified list-view item. Use this macro or send the LVM_SETITEMINDEXSTATE message explicitly. /// /// /// Type: HWND /// A handle to the list-view control. /// /// /// Type: LVITEMINDEX* /// /// A pointer to an LVITEMINDEX structure for the item. The caller is responsible for allocating this structure and setting the members. /// /// /// /// Type: UINT /// The state to set on the item as one or more (as a bitwise combination) of the List-View Item States flags. /// /// /// Type: UINT /// /// The valid bits of the state specified by parameter data. For more information, see the stateMask member of the LVITEM) structure. /// /// /// /// None /// // https://docs.microsoft.com/en-us/windows/desktop/api/commctrl/nf-commctrl-listview_setitemindexstate void // ListView_SetItemIndexState( hwndLV, plvii, data, mask ); [PInvokeData("commctrl.h", MSDNShortId = "listview_setitemindexstate")] public static HRESULT ListView_SetItemIndexState(HWND hwndLV, in LVITEMINDEX plvii, uint data, ListViewItemState mask) => new HRESULT(SendMessage(hwndLV, (uint)ListViewMessage.LVM_SETITEMINDEXSTATE, in plvii, new LVITEM(0) { stateMask = mask, state = data }).ToInt32()); /// /// Contains information used when searching for a list-view item. This structure is identical to LV_FINDINFO but has been renamed /// to fit standard naming conventions. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774745")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct LVFINDINFO { /// Type of search to perform. public ListViewFindInfoFlag flags; /// /// Address of a null-terminated string to compare with the item text. It is valid only if LVFI_STRING or LVFI_PARTIAL is set in /// the flags member. /// public string psz; /// /// Value to compare with the lParam member of a list-view item's LVITEM structure. It is valid only if LVFI_PARAM is set in the /// flags member. /// public IntPtr lParam; /// POINT structure with the initial search position. It is valid only if LVFI_NEARESTXY is set in the flags member. public Point pt; /// Virtual key code that specifies the direction to search. public ConsoleKey vkDirection; /// Initializes a new instance of the struct. /// The search string. /// if set to true if is the beginning of an item's text. /// if set to true continues the search at the beginning if no match is found. public LVFINDINFO(string searchString, bool allowPartial, bool wrap) : this() { psz = searchString; flags = ListViewFindInfoFlag.LVFI_STRING; if (allowPartial) flags |= ListViewFindInfoFlag.LVFI_PARTIAL; if (wrap) flags |= ListViewFindInfoFlag.LVFI_WRAP; } /// Initializes a new instance of the struct. /// The value to compare to the lParam member of a list-view item. public LVFINDINFO(IntPtr lParam) : this() { flags = ListViewFindInfoFlag.LVFI_PARAM; this.lParam = lParam; } /// Initializes a new instance of the struct. /// The initial search position. /// The search direction. public LVFINDINFO(Point point, ConsoleKey searchDirection) : this() { flags = ListViewFindInfoFlag.LVFI_NEARESTXY; pt = point; vkDirection = searchDirection; } } /// Contains information about the display of groups in a list-view control. [PInvokeData("Commctrl.h", MSDNShortId = "bb774752")] [StructLayout(LayoutKind.Sequential)] public struct LVGROUPMETRICS { /// Size of the LVGROUPMETRICS structure. public uint cbSize; /// Flags that specify which members contain or are to receive valid data. public ListViewGroupMetricsMask mask; /// Specifies the width of the left border in icon, small icon, or tile view. public int Left; /// Specifies the width of the top border in all group views. public int Top; /// Specifies the width of the right border in icon, small icon, or tile view. public int Right; /// Specifies the width of the bottom border in all group views. public int Bottom; /// Specifies the color of the left border. Not implemented. public uint crLeft; /// Specifies the color of the top border. Not implemented. public uint crTop; /// Specifies the color of the right border. Not implemented. public uint crRight; /// Specifies the color of the bottom border. Not implemented. public uint crBottom; /// Specifies the color of the header text. Not implemented. public uint crHeader; /// Specifies the color of the footer text. Not implemented. public uint crFooter; /// Initializes a new instance of the class. /// The mask. public LVGROUPMETRICS(ListViewGroupMetricsMask mask = ListViewGroupMetricsMask.LVGMF_NONE) : this() { cbSize = (uint)Marshal.SizeOf(typeof(LVGROUPMETRICS)); this.mask = mask; } /// Initializes a new instance of the class. /// The width of the left border. /// The width of the top border. /// The width of the right border. /// The width of the bottom border. public LVGROUPMETRICS(int left, int top, int right, int bottom) : this() { cbSize = (uint)Marshal.SizeOf(typeof(LVGROUPMETRICS)); SetBorderSize(left, top, right, bottom); } /// Sets the size of the border. /// The left. /// The top. /// The right. /// The bottom. public void SetBorderSize(int left, int top, int right, int bottom) { mask = ListViewGroupMetricsMask.LVGMF_BORDERSIZE; Left = left; Top = top; Right = right; Bottom = bottom; } } /// /// Contains information about a hit test. This structure has been extended to accommodate subitem hit-testing. It is used in /// association with the LVM_HITTEST and LVM_SUBITEMHITTEST messages and their related macros. This structure supersedes the /// LVHITTESTINFO structure. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774754")] [StructLayout(LayoutKind.Sequential)] public struct LVHITTESTINFO { /// The position to hit test, in client coordinates. public Point pt; /// /// The variable that receives information about the results of a hit test. This member can be one or more of the following values: /// /// You can use LVHT_ABOVE, LVHT_BELOW, LVHT_TOLEFT, and LVHT_TORIGHT to determine whether to scroll the contents of a list-view /// control.Two of these values may be combined. For example, if the position is above and to the left of the client area, you /// could use both LVHT_ABOVE and LVHT_TOLEFT. /// /// /// You can test for LVHT_ONITEM to determine whether a specified position is over a list-view item. This value is a bitwise-OR /// operation on LVHT_ONITEMICON, LVHT_ONITEMLABEL, and LVHT_ONITEMSTATEICON. /// /// public ListViewHitTestFlag flags; /// /// Receives the index of the matching item. Or if hit-testing a subitem, this value represents the subitem's parent item. /// public int iItem; /// Version 4.70. Receives the index of the matching subitem. When hit-testing an item, this member will be zero. public int iSubItem; /// /// Windows Vista. Group index of the item hit (read only). Valid only for owner data. If the point is within an item that is /// displayed in multiple groups then iGroup will specify the group index of the item. /// public int iGroup; /// Initializes a new instance of the class. /// The pt. public LVHITTESTINFO(Point pt) : this() => this.pt = pt; } /// Used to describe insertion points. [PInvokeData("Commctrl.h", MSDNShortId = "bb774758")] [StructLayout(LayoutKind.Sequential)] public struct LVINSERTMARK { /// Size of the LVINSERTMARK structure. public uint cbSize; /// Flag that specifies where the insertion point should appear. public ListViewInsertMarkFlag dwFlags; /// Item next to which the insertion point appears. If this member contains -1, there is no insertion point. public int iItem; /// Reserved. Must be zero. public uint dwReserved; /// Initializes a new instance of the struct. /// Index at which to insert the item. /// if set to true the insertion point appears after the item specified. public LVINSERTMARK(int insertAtItem, bool insertAfter = false) : this() { cbSize = (uint)Marshal.SizeOf(typeof(LVINSERTMARK)); dwFlags = insertAfter ? ListViewInsertMarkFlag.LVIM_AFTER : ListViewInsertMarkFlag.LVIM_BEFORE; iItem = insertAtItem; } } /// Helper structure for to easily capture column order and format information. [PInvokeData("Commctrl.h", MSDNShortId = "bb774760")] [StructLayout(LayoutKind.Sequential)] public struct LVITEMCOLUMNINFO { /// The column index public uint columnIndex; /// /// Windows Vista: Not implemented. Windows 7 and later: A flag specifying the format of this column in extended tile view. /// public ListViewColumnFormat format; /// Initializes a new instance of the struct. /// Index of the column. /// The format of the column. public LVITEMCOLUMNINFO(uint colIdx, ListViewColumnFormat fmt = 0) { columnIndex = colIdx; format = fmt; } } /// Contains index information about a list-view item. [PInvokeData("Commctrl.h", MSDNShortId = "bb761385")] [StructLayout(LayoutKind.Sequential)] public struct LVITEMINDEX { /// The index of the item. public int iItem; /// The index of the group the item belongs to. public int iGroup; } /// Provides information about a list-view control when it is displayed in tile view. [PInvokeData("Commctrl.h", MSDNShortId = "bb774768")] [StructLayout(LayoutKind.Sequential)] public struct LVTILEVIEWINFO { /// Size of the LVTILEVIEWINFO structure. public uint cbSize; /// Mask that determines which members are valid. This member may be one of the following values. public ListViewTileViewMask dwMask; /// Flags that determines how the tiles are sized in tile view. This member may be one of the following values. public ListViewTileViewFlag dwFlags; /// Size of an individual tile. Values for dimensions not specified as fixed in dwFlags are ignored. public SIZE sizeTile; /// Maximum number of text lines in each item label, not counting the title. public int cLines; /// RECT that contains coordinates of the label margin. public RECT rcLabelMargin; /// Initializes a new instance of the struct. /// The mask. public LVTILEVIEWINFO(ListViewTileViewMask mask) : this() { cbSize = (uint)Marshal.SizeOf(typeof(LVTILEVIEWINFO)); dwMask = mask; } /// Gets or sets a value indicating whether to size the tiles automatically. /// true if tiles are automatically sized; otherwise, false. public bool AutoSize { get => dwFlags.IsFlagSet(ListViewTileViewFlag.LVTVIF_AUTOSIZE); set { dwFlags = ListViewTileViewFlag.LVTVIF_AUTOSIZE; dwMask |= ListViewTileViewMask.LVTVIM_TILESIZE; sizeTile.cy = sizeTile.cx = 0; } } /// Gets or sets the size of an individual tile. /// The size of an individual tile. public Size TileSize { get => sizeTile; set { sizeTile = value; dwMask |= ListViewTileViewMask.LVTVIM_TILESIZE; dwFlags |= ListViewTileViewFlag.LVTVIF_FIXEDSIZE; } } /// Gets or sets the height of an individual tile. /// The height of an individual tile. public int TileHeight { get => sizeTile.cy; set { sizeTile.cy = value; dwMask |= ListViewTileViewMask.LVTVIM_TILESIZE; dwFlags |= ListViewTileViewFlag.LVTVIF_FIXEDHEIGHT; } } /// Gets or sets the width of an individual tile. /// The width of an individual tile. public int TileWidth { get => sizeTile.cx; set { sizeTile.cx = value; dwMask |= ListViewTileViewMask.LVTVIM_TILESIZE; dwFlags |= ListViewTileViewFlag.LVTVIF_FIXEDWIDTH; } } /// Gets or sets the maximum number of text lines in each item label, not counting the title. /// The maximum number of text lines in each item label, not counting the title. public int MaxTextLines { get => cLines; set { cLines = value; dwMask |= ListViewTileViewMask.LVTVIM_COLUMNS; } } /// Gets or sets the tile padding. /// The tile padding. public RECT TilePadding { get => rcLabelMargin; set { rcLabelMargin = value; dwMask |= ListViewTileViewMask.LVTVIM_LABELMARGIN; } } } /// /// Contains information about a list-view notification message. This structure is the same as the NM_LISTVIEW structure but has /// been renamed to fit standard naming conventions. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774773")] [StructLayout(LayoutKind.Sequential)] public struct NMLISTVIEW { /// NMHDR structure that contains information about this notification message public NMHDR hdr; /// Identifies the list-view item, or -1 if not used. public int iItem; /// Identifies the subitem, or zero if none. public int iSubItem; /// /// New item state. This member is zero for notification messages that do not use it. For a list of possible values, see /// List-View Item States. /// public ListViewItemState uNewState; /// /// Old item state. This member is zero for notification messages that do not use it. For a list of possible values, see /// List-View Item States. /// public ListViewItemState uOldState; /// /// Set of flags that indicate the item attributes that have changed. This member is zero for notifications that do not use it. /// Otherwise, it can have the same values as the mask member of the LVITEM structure. /// public ListViewItemMask uChanged; /// /// POINT structure that indicates the location at which the event occurred. This member is undefined for notification messages /// that do not use it. /// public Point ptAction; /// Application-defined value of the item. This member is undefined for notification messages that do not use it. public IntPtr lParam; } /// /// Contains information about the background image of a list-view control. This structure is used for both setting and retrieving /// background image information. /// /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774742")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public sealed class LVBKIMAGE : IDisposable { /// /// This member may be one or more of the following flags. You can use the LVBKIF_SOURCE_MASK value to mask off all but the /// source flags. You can use the LVBKIF_STYLE_MASK value to mask off all but the style flags. /// public ListViewBkImageFlag ulFlags; /// The handle of the background bitmap. This member is valid only if the LVBKIF_SOURCE_HBITMAP flag is set in ulFlags. public HBITMAP hBmp = IntPtr.Zero; /// /// Address of a NULL-terminated string that contains the URL of the background image. This member is valid only if the /// LVBKIF_SOURCE_URL flag is set in ulFlags. This member must be initialized to point to the buffer that contains or receives /// the text before sending the message. /// public StrPtrAuto pszImage; /// Size of the buffer at the address in pszImage. If information is being sent to the control, this member is ignored. public uint cchImageMax; /// /// Percentage of the control's client area that the image should be offset horizontally. For example, at 0 percent, the image /// will be displayed against the left edge of the control's client area. At 50 percent, the image will be displayed /// horizontally centered in the control's client area. At 100 percent, the image will be displayed against the right edge of /// the control's client area. This member is valid only when LVBKIF_STYLE_NORMAL is specified in ulFlags. If both /// LVBKIF_FLAG_TILEOFFSET and LVBKIF_STYLE_TILE are specified in ulFlags, then the value specifies the pixel, not percentage /// offset, of the first tile. Otherwise, the value is ignored. /// public int xOffset; /// /// Percentage of the control's client area that the image should be offset vertically. For example, at 0 percent, the image /// will be displayed against the top edge of the control's client area. At 50 percent, the image will be displayed vertically /// centered in the control's client area. At 100 percent, the image will be displayed against the bottom edge of the control's /// client area. This member is valid only when LVBKIF_STYLE_NORMAL is specified in ulFlags. If both LVBKIF_FLAG_TILEOFFSET and /// LVBKIF_STYLE_TILE are specified in ulFlags, then the value specifies the pixel, not percentage offset, of the first tile. /// Otherwise, the value is ignored. /// public int yOffset; /// Initializes a new instance of the class. /// The BMP. /// if set to true [is watermark]. /// if set to true [is watermark alpha blended]. public LVBKIMAGE(Bitmap bmp, bool isWatermark, bool isWatermarkAlphaBlended) { Bitmap = bmp; ulFlags = isWatermark ? ListViewBkImageFlag.LVBKIF_TYPE_WATERMARK : ListViewBkImageFlag.LVBKIF_SOURCE_HBITMAP; if (isWatermark && isWatermarkAlphaBlended) ulFlags |= ListViewBkImageFlag.LVBKIF_FLAG_ALPHABLEND; } /// Initializes a new instance of the class. /// The BMP. /// if set to true [is tiled]. public LVBKIMAGE(Bitmap bmp, bool isTiled) { Bitmap = bmp; ulFlags = ListViewBkImageFlag.LVBKIF_SOURCE_HBITMAP; if (isTiled) ulFlags |= ListViewBkImageFlag.LVBKIF_STYLE_TILE; } /// Initializes a new instance of the class. /// The URL. /// if set to true [is tiled]. public LVBKIMAGE(string url, bool isTiled) { Url = url; ulFlags = ListViewBkImageFlag.LVBKIF_SOURCE_URL; if (isTiled) ulFlags |= ListViewBkImageFlag.LVBKIF_STYLE_TILE; } /// Initializes a new instance of the class. public LVBKIMAGE() : this(ListViewBkImageFlag.LVBKIF_SOURCE_NONE) { } /// Initializes a new instance of the class. /// The flags. public LVBKIMAGE(ListViewBkImageFlag flags) { ulFlags = flags; if (ulFlags.IsFlagSet(ListViewBkImageFlag.LVBKIF_SOURCE_URL)) pszImage = new StrPtrAuto(cchImageMax = 1024); } /// Gets or sets the bitmap. /// The bitmap. public Bitmap Bitmap { get => hBmp.IsNull ? null : System.Drawing.Image.FromHbitmap((IntPtr)hBmp); set => hBmp = value?.GetHbitmap() ?? IntPtr.Zero; } /// Gets or sets the URL. /// The URL. public string Url { get => pszImage.ToString(); set => EnumExtensions.SetFlags(ref ulFlags, ListViewBkImageFlag.LVBKIF_SOURCE_URL, pszImage.Assign(value, out cchImageMax)); } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() => pszImage.Free(); } /// /// Contains information about a column in report view. This structure is used both for creating and manipulating columns. This /// structure supersedes the LV_COLUMN structure. /// /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774743")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public sealed class LVCOLUMN : IDisposable { /// /// Variable specifying which members contain valid information. This member can be zero, or one or more of the following values: /// public ListViewColumMask mask; /// /// Alignment of the column header and the subitem text in the column. The alignment of the leftmost column is always /// LVCFMT_LEFT; it cannot be changed. This member can be a combination of the following values. Note that not all combinations /// are valid. /// public ListViewColumnFormat fmt; /// Width of the column, in pixels. public int cx; /// /// If column information is being set, this member is the address of a null-terminated string that contains the column header /// text. If the structure is receiving information about a column, this member specifies the address of the buffer that /// receives the column header text. /// public StrPtrAuto pszText; /// /// Size in TCHARs of the buffer pointed to by the pszText member. If the structure is not receiving information about a column, /// this member is ignored. /// public uint cchTextMax; /// Index of subitem associated with the column. public int iSubItem; /// /// Version 4.70. Zero-based index of an image within the image list. The specified image will appear within the column. /// public int iImage; /// /// Version 4.70. Zero-based column offset. Column offset is in left-to-right order. For example, zero indicates the leftmost column. /// public int iOrder; /// Windows Vista. Minimum width of the column in pixels. public int cxMin; /// /// Windows Vista. Application-defined value typically used to store the default width of the column. This member is ignored by /// the list-view control. /// public int cxDefault; /// /// Windows Vista. Read-only. The ideal width of the column in pixels, as the column may currently be autosized to a lesser width. /// public int cxIdeal; /// Initializes a new instance of the class. /// The mask. [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] public LVCOLUMN(ListViewColumMask mask) { this.mask = mask; if (mask.IsFlagSet(ListViewColumMask.LVCF_TEXT)) pszText = new StrPtrAuto(cchTextMax = 1024); } /// Gets or sets the format. /// The format. public ListViewColumnFormat Format { get => fmt; set { fmt = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_FMT); } } /// Gets or sets the header text. /// /// The header text. Setting this value will free any previous buffer and will allocate a new buffer sufficient to hold the string. /// public string Text { get => pszText.ToString(); set => EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_TEXT, pszText.Assign(value, out cchTextMax)); } /// Gets or sets the index of subitem associated with the column. /// The index of subitem. public int Subitem { get => iSubItem; set { iSubItem = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_SUBITEM); } } /// Gets or sets the zero-based index of an image within the image list. /// The index of and image in the image list. public int ImageListIndex { get => iImage; set { iImage = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_IMAGE); } } /// Gets or sets the column position. /// The column position. public int ColumnPosition { get => iOrder; set { iOrder = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_ORDER); } } /// Gets or sets the default width. /// The default width. public int DefaultWidth { get => cxDefault; set { cxDefault = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_DEFAULTWIDTH); } } /// Gets or sets the minimum width. /// The minimum width. public int MinWidth { get => cxMin; set { cxMin = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_MINWIDTH); } } /// Gets or sets the ideal width. /// The ideal width. public int IdealWidth { get => cxIdeal; set { cxIdeal = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_IDEALWIDTH); } } /// Gets or sets the width. /// The width. public int Width { get => cx; set { cx = value; EnumExtensions.SetFlags(ref mask, ListViewColumMask.LVCF_WIDTH); } } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() => pszText.Free(); } /// Used to set and retrieve groups. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774769")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public sealed class LVGROUP : IDisposable { /// Size of this structure, in bytes. public int cbSize = Marshal.SizeOf(typeof(LVGROUP)); /// Mask that specifies which members of the structure are valid input. public ListViewGroupMask mask; /// /// Pointer to a null-terminated string that contains the header text when item information is being set. If group information /// is being retrieved, this member specifies the address of the buffer that receives the header text. /// public StrPtrAuto pszHeader; /// /// Size in TCHARs of the buffer pointed to by the pszHeader member. If the structure is not receiving information about a /// group, this member is ignored. /// public uint cchHeader; /// /// Pointer to a null-terminated string that contains the footer text when item information is being set. If group information /// is being retrieved, this member specifies the address of the buffer that receives the footer text. /// public StrPtrAuto pszFooter; /// /// Size in TCHARs of the buffer pointed to by the pszFooter member. If the structure is not receiving information about a /// group, this member is ignored. /// public uint cchFooter; /// ID of the group. public int iGroupId; /// /// Mask used with LVM_GETGROUPINFO and LVM_SETGROUPINFO to specify which flags in the state value are being retrieved or set. /// public ListViewGroupState stateMask; /// Flag that can have one of the following values: public ListViewGroupState state; /// /// Indicates the alignment of the header or footer text for the group. It can have one or more of the following values. Use one /// of the header flags. Footer flags are optional. /// public ListViewGroupAlignment uAlign; /// /// Pointer to a null-terminated string that contains the subtitle text when item information is being set. If group information /// is being retrieved, this member specifies the address of the buffer that receives the subtitle text. This element is drawn /// under the header text. /// public StrPtrAuto pszSubtitle; /// /// Size, in TCHARs, of the buffer pointed to by the pszSubtitle member. If the structure is not receiving information about a /// group, this member is ignored. /// public uint cchSubtitle; /// /// Pointer to a null-terminated string that contains the text for a task link when item information is being set. If group /// information is being retrieved, this member specifies the address of the buffer that receives the task text. This item is /// drawn right-aligned opposite the header text. When clicked by the user, the task link generates an LVN_LINKCLICK notification. /// public StrPtrAuto pszTask; /// /// Size in TCHARs of the buffer pointed to by the pszTask member. If the structure is not receiving information about a group, /// this member is ignored. /// public uint cchTask; /// /// Pointer to a null-terminated string that contains the top description text when item information is being set. If group /// information is being retrieved, this member specifies the address of the buffer that receives the top description text. This /// item is drawn opposite the title image when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER. /// public StrPtrAuto pszDescriptionTop; /// /// Size in TCHARs of the buffer pointed to by the pszDescriptionTop member. If the structure is not receiving information about /// a group, this member is ignored. /// public uint cchDescriptionTop; /// /// Pointer to a null-terminated string that contains the bottom description text when item information is being set. If group /// information is being retrieved, this member specifies the address of the buffer that receives the bottom description text. /// This item is drawn under the top description text when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER. /// public StrPtrAuto pszDescriptionBottom; /// /// Size in TCHARs of the buffer pointed to by the pszDescriptionBottom member. If the structure is not receiving information /// about a group, this member is ignored. /// public uint cchDescriptionBottom; /// Index of the title image in the control imagelist. public int iTitleImage; /// Index of the extended image in the control imagelist. public int iExtendedImage; /// Read-only. public int iFirstItem; /// Read-only in non-owner data mode. public uint cItems; /// /// NULL if group is not a subset. Pointer to a null-terminated string that contains the subset title text when item information /// is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the /// subset title text. /// public StrPtrAuto pszSubsetTitle; /// /// Size in TCHARs of the buffer pointed to by the pszSubsetTitle member. If the structure is not receiving information about a /// group, this member is ignored. /// public uint cchSubsetTitle; /*public LVGROUP(ListViewGroup grp) : this(ListViewGroupMask.LVGF_NONE, grp.Header) { HeaderAlignment = grp.HeaderAlignment; var pi = grp.GetType().GetProperty("ID", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, typeof(int), Type.EmptyTypes, null); if (pi != null) ID = (int)pi.GetValue(grp, null); }*/ /// Initializes a new instance of the class. /// The mask. /// The header text. [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] public LVGROUP(ListViewGroupMask mask = ListViewGroupMask.LVGF_NONE, string header = null) { this.mask = mask; if (header != null) Header = header; else if ((mask & ListViewGroupMask.LVGF_HEADER) != 0) pszHeader = new StrPtrAuto(cchHeader = 1024); if ((mask & ListViewGroupMask.LVGF_FOOTER) != 0) pszFooter = new StrPtrAuto(cchFooter = 1024); if ((mask & ListViewGroupMask.LVGF_SUBTITLE) != 0) pszSubtitle = new StrPtrAuto(cchSubtitle = 1024); if ((mask & ListViewGroupMask.LVGF_TASK) != 0) pszTask = new StrPtrAuto(cchTask = 1024); if ((mask & ListViewGroupMask.LVGF_DESCRIPTIONBOTTOM) != 0) pszDescriptionBottom = new StrPtrAuto(cchDescriptionBottom = 1024); if ((mask & ListViewGroupMask.LVGF_DESCRIPTIONTOP) != 0) pszDescriptionTop = new StrPtrAuto(cchDescriptionTop = 1024); } /// Gets or sets the bottom description text. /// The bottom description text. public string DescriptionBottom { get => pszDescriptionBottom.ToString(); [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_DESCRIPTIONBOTTOM, pszDescriptionBottom.Assign(value, out cchDescriptionBottom)); } /// Gets or sets the top description text. /// The top description text. public string DescriptionTop { get => pszDescriptionTop.ToString(); [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_DESCRIPTIONTOP, pszDescriptionTop.Assign(value, out cchDescriptionTop)); } /// Gets or sets the footer. /// The footer. public string Footer { get => pszFooter.ToString(); [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_FOOTER, pszFooter.Assign(value, out cchFooter)); } /// Gets or sets the identifier. /// The identifier. public int ID { get => iGroupId; set { iGroupId = value; mask |= ListViewGroupMask.LVGF_GROUPID; } } /// Gets or sets the index of the title image. /// The index of the title image. public int TitleImageIndex { get => iTitleImage; set { iTitleImage = value; mask |= ListViewGroupMask.LVGF_TITLEIMAGE; } } /// Gets or sets the index of the extended image. /// The index of the extended image. public int ExtendedImageIndex { get => iExtendedImage; set { iExtendedImage = value; mask |= ListViewGroupMask.LVGF_EXTENDEDIMAGE; } } /// Gets the first item. /// The first item. public int FirstItem => iFirstItem; /// Gets the item count. /// The item count. public uint ItemCount => cItems; /// Gets or sets the alignment. /// The alignment. public ListViewGroupAlignment Alignment { get => uAlign; set { uAlign = value; mask |= ListViewGroupMask.LVGF_ALIGN; } } /// Gets or sets the header text. /// The header text. public string Header { get => pszHeader.ToString(); set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_HEADER, pszHeader.Assign(value, out cchHeader)); } /// Gets or sets the subtitle. /// The subtitle. public string Subtitle { get => pszSubtitle.ToString(); set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_SUBTITLE, pszSubtitle.Assign(value, out cchSubtitle)); } /// Gets or sets the task link text. /// The task link text. public string TaskLink { get => pszTask.ToString(); [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] set => EnumExtensions.SetFlags(ref mask, ListViewGroupMask.LVGF_TASK, pszTask.Assign(value, out cchTask)); } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public void Dispose() { pszHeader.Free(); pszFooter.Free(); pszSubtitle.Free(); pszTask.Free(); pszDescriptionBottom.Free(); pszDescriptionTop.Free(); } /// Sets the state. /// State of the g. /// if set to true [on]. public void SetState(ListViewGroupState gState, bool on = true) { mask |= ListViewGroupMask.LVGF_STATE; stateMask |= gState; EnumExtensions.SetFlags(ref state, gState, on); } } /// /// Specifies or receives the attributes of a list-view item. This structure has been updated to support a new mask value /// (LVIF_INDENT) that enables item indenting. This structure supersedes the LV_ITEM structure. /// /// [PInvokeData("Commctrl.h", MSDNShortId = "bb774760")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public sealed class LVITEM : IDisposable { private const int MAX_COLS = 20; private const int OverlayShift = 8; private const int StateImageShift = 12; /// /// Set of flags that specify which members of this structure contain data to be set or which members are being requested. This /// member can have one or more of the following flags set: /// public ListViewItemMask mask; /// Zero-based index of the item to which this structure refers. public int iItem; /// /// One-based index of the subitem to which this structure refers, or zero if this structure refers to an item rather than a subitem. /// public int iSubItem; /// /// Indicates the item's state, state image, and overlay image. The stateMask member indicates the valid bits of this member. /// Bits 0 through 7 of this member contain the item state flags. This can be one or more of the item state values. /// /// Bits 8 through 11 of this member specify the one-based overlay image index. Both the full-sized icon image list and the /// small icon image list can have overlay images. The overlay image is superimposed over the item's icon image. If these bits /// are zero, the item has no overlay image. To isolate these bits, use the LVIS_OVERLAYMASK mask. To set the overlay image /// index in this member, you should use the INDEXTOOVERLAYMASK macro. The image list's overlay images are set with the /// ImageList_SetOverlayImage function. /// /// /// Bits 12 through 15 of this member specify the state image index. The state image is displayed next to an item's icon to /// indicate an application-defined state. If these bits are zero, the item has no state image. To isolate these bits, use the /// LVIS_STATEIMAGEMASK mask. To set the state image index, use the INDEXTOSTATEIMAGEMASK macro. The state image index specifies /// the index of the image in the state image list that should be drawn. The state image list is specified with the /// LVM_SETIMAGELIST message. /// /// public uint state; /// /// Value specifying which bits of the state member will be retrieved or modified. For example, setting this member to /// LVIS_SELECTED will cause only the item's selection state to be retrieved. /// /// This member allows you to modify one or more item states without having to retrieve all of the item states first.For /// example, setting this member to LVIS_SELECTED and state to zero will cause the item's selection state to be cleared, but /// none of the other states will be affected. /// /// To retrieve or modify all of the states, set this member to(UINT)-1. /// You can use the macro ListView_SetItemState both to set and to clear bits. /// public ListViewItemState stateMask; /// /// If the structure specifies item attributes, pszText is a pointer to a null-terminated string containing the item text. When /// responding to an LVN_GETDISPINFO notification, be sure that this pointer remains valid until after the next notification has /// been received. /// /// If the structure receives item attributes, pszText is a pointer to a buffer that receives the item text. Note that although /// the list-view control allows any length string to be stored as item text, only the first 260 TCHARs are displayed. /// /// /// If the value of pszText is LPSTR_TEXTCALLBACK, the item is a callback item.If the callback text changes, you must explicitly /// set pszText to LPSTR_TEXTCALLBACK and notify the list-view control of the change by sending an LVM_SETITEM or /// LVM_SETITEMTEXT message. /// /// /// Do not set pszText to LPSTR_TEXTCALLBACK if the list-view control has the LVS_SORTASCENDING or LVS_SORTDESCENDING style. /// /// public StrPtrAuto pszText; /// /// Number of TCHARs in the buffer pointed to by pszText, including the terminating NULL. /// /// This member is only used when the structure receives item attributes.It is ignored when the structure specifies item /// attributes.For example, cchTextMax is ignored during LVM_SETITEM and LVM_INSERTITEM.It is read-only during LVN_GETDISPINFO /// and other LVN_ notifications. /// /// Never copy more than cchTextMax TCHARs—where cchTextMax includes the terminating NULL—into pszText during an LVN_ /// notification, otherwise your program can fail. /// public uint cchTextMax; /// /// Index of the item's icon in the control's image list. This applies to both the large and small image list. If this member is /// the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the list-view control sends /// the parent an LVN_GETDISPINFO notification code to retrieve the index when it needs to display the image. /// public int iImage; /// /// Value specific to the item. If you use the LVM_SORTITEMS message, the list-view control passes this value to the /// application-defined comparison function. You can also use the LVM_FINDITEM message to search a list-view control for an item /// with a specified lParam value. /// public IntPtr lParam; /// /// Version 4.70. Number of image widths to indent the item. A single indentation equals the width of an item image. Therefore, /// the value 1 indents the item by the width of one image, the value 2 indents by two images, and so on. Note that this field /// is supported only for items. Attempting to set subitem indentation will cause the calling function to fail. /// public int iIndent; /// /// Version 6.0 Identifier of the group that the item belongs to, or one of the following values: I_GROUPIDCALLBACK = The /// listview control sends the parent an LVN_GETDISPINFO notification code to retrieve the index of the group; I_GROUPIDNONE = /// The item does not belong to a group. /// public int iGroupId; /// /// Version 6.0 Number of data columns (subitems) to display for this item in tile view. The maximum value is 20. If this value /// is I_COLUMNSCALLBACK, the size of the column array and the array itself (puColumns) are obtained by sending a /// LVN_GETDISPINFO notification. /// public uint cColumns; /// /// Version 6.0 A pointer to an array of column indices, specifying which columns are displayed for this item, and the order of /// those columns. /// public IntPtr puColumns; /// /// Windows Vista: Not implemented. Windows 7 and later: A pointer to an array of the following flags (alone or in combination), /// specifying the format of each subitem in extended tile view. /// public IntPtr piColFmt; /// Windows Vista: Group index of the item. Valid only for owner data/callback (single item in multiple groups). public int iGroup; /// Initializes a new instance of the class. /// Zero-based index of the item. /// One-based index of the subitem. /// The mask of items to retrieve. /// The state items to retrieve. public LVITEM(int item, int subitem, ListViewItemMask mask = ListViewItemMask.LVIF_ALL, ListViewItemState stateMask = ListViewItemState.LVIS_ALL) { this.mask = mask; if (mask.IsFlagSet(ListViewItemMask.LVIF_TEXT)) pszText = new StrPtrAuto(cchTextMax = 1024); if (mask.IsFlagSet(ListViewItemMask.LVIF_COLUMNS)) puColumns = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * MAX_COLS); if (mask.IsFlagSet(ListViewItemMask.LVIF_COLFMT)) piColFmt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * MAX_COLS); iItem = item; iSubItem = subitem; this.stateMask = stateMask; } /// Initializes a new instance of the class. /// Zero-based index of the item. /// One-based index of the subitem or zero if this structure refers to an item rather than a subitem. /// The item text. public LVITEM(int item, int subitem = 0, string text = null) { iItem = item; iSubItem = subitem; if (text != null) Text = text; } /// Gets or sets the group identifier. /// The group identifier. public int GroupId { get => iGroupId; set { iGroupId = value; EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_GROUPID); } } /// Gets or sets the index of the image. /// The index of the image. public int ImageIndex { get => iImage; set { iImage = value; EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_IMAGE); } } /// Gets or sets the indent. /// The indent. public int Indent { get => iIndent; set { iIndent = value; EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_INDENT); } } /// Gets or sets the l parameter. /// The l parameter. public IntPtr LParam { get => lParam; set { lParam = value; EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_PARAM); } } /// Gets or sets the text. /// The text. public string Text { get => pszText.ToString(); set => EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_TEXT, pszText.Assign(value, out cchTextMax)); } /// Gets or sets the tile columns. /// The tile columns. public LVITEMCOLUMNINFO[] TileColumns { get { var ret = new LVITEMCOLUMNINFO[cColumns]; if (cColumns == 0) return ret; var cols = puColumns.ToArray((int)cColumns); var fmts = piColFmt.ToArray((int)cColumns); for (var i = 0; i < cColumns; i++) ret[i] = new LVITEMCOLUMNINFO((uint)(cols?[i] ?? 0), (ListViewColumnFormat)(fmts?[i] ?? 0)); return ret; } set { Marshal.FreeHGlobal(puColumns); Marshal.FreeHGlobal(piColFmt); cColumns = (uint)(value?.Length ?? 0); puColumns = piColFmt = IntPtr.Zero; if (value == null) { EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_COLFMT | ListViewItemMask.LVIF_COLUMNS, false); return; } var cols = new int[cColumns]; var fmts = new int[cColumns]; var hasFmts = false; for (var i = 0; i < cColumns; i++) { cols[i] = (int)value[i].columnIndex; fmts[i] = (int)value[i].format; if (fmts[i] != 0) hasFmts = true; } if (cColumns > 0) { puColumns = cols.MarshalToPtr(Marshal.AllocHGlobal, out _); } EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_COLUMNS); if (hasFmts) { piColFmt = fmts.MarshalToPtr(Marshal.AllocHGlobal, out _); EnumExtensions.SetFlags(ref mask, ListViewItemMask.LVIF_COLFMT); } } } /// Gets the state. /// The state. /// The value of the specified state. private bool GetState(ListViewItemState state) => StateFlags.IsFlagSet(state); /// Sets the state. /// The state value to set. /// true to set, false to unset. private void SetState(ListViewItemState state, bool value) { mask |= ListViewItemMask.LVIF_STATE; stateMask |= state; this.state = (uint)StateFlags.SetFlags(state, value) | ((uint)state & 0xFFFFFF00); } /// Gets the state flags. /// The state flags. public ListViewItemState StateFlags => (ListViewItemState)(state & 0x000000FF); /// Gets or sets a value indicating whether the item is marked for a cut-and-paste operation. /// true if marked for a cut-and-paste operation; otherwise, false. public bool CutOrPaste { get => GetState(ListViewItemState.LVIS_CUT); set => SetState(ListViewItemState.LVIS_CUT, value); } /// Gets or sets a value indicating whether the item is highlighted as a drag-and-drop target. /// true if highlighted as a drag-and-drop target; otherwise, false. public bool DropHighlighted { get => GetState(ListViewItemState.LVIS_DROPHILITED); set => SetState(ListViewItemState.LVIS_DROPHILITED, value); } /// Gets or sets a value indicating whether this item has the focus. /// true if focused; otherwise, false. public bool Focused { get => GetState(ListViewItemState.LVIS_FOCUSED); set => SetState(ListViewItemState.LVIS_FOCUSED, value); } /// Gets or sets a value indicating whether this item is selected. /// true if selected; otherwise, false. public bool Selected { get => GetState(ListViewItemState.LVIS_SELECTED); set => SetState(ListViewItemState.LVIS_SELECTED, 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 & (uint)ListViewItemState.LVIS_OVERLAYMASK) >> OverlayShift; set { if (value > 0xF) throw new ArgumentOutOfRangeException(nameof(OverlayImageIndex), "Overlay image index must be between 0 and 15"); mask |= ListViewItemMask.LVIF_STATE; stateMask |= ListViewItemState.LVIS_OVERLAYMASK; state = (value << OverlayShift) | (state & ~(uint)ListViewItemState.LVIS_OVERLAYMASK); } } /// 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 & (uint)ListViewItemState.LVIS_STATEIMAGEMASK) >> StateImageShift; set { if (value > 0xF) throw new ArgumentOutOfRangeException(nameof(StateImageIndex), "State image index must be between 0 and 15"); mask |= ListViewItemMask.LVIF_STATE; stateMask |= ListViewItemState.LVIS_STATEIMAGEMASK; state = (value << StateImageShift) | (state & ~(uint)ListViewItemState.LVIS_STATEIMAGEMASK); } } /// Returns a that represents this instance. /// A that represents this instance. public override string ToString() => $"LVITEM: pszText={Text}; iItem={iItem}; iSubItem={iSubItem}; state={state}; iGroupId={iGroupId}; cColumns={cColumns}"; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() { Marshal.FreeHGlobal(puColumns); Marshal.FreeHGlobal(piColFmt); pszText.Free(); } } } }