WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Boxes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ListView UDFs



; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; >                                                                                                                                       <
; >              ....IFICantBYTE's ListView UDF Suite - 39 UDFs in Release v2.9.1 for WinBatch                                            <
; >                                                                                                                                       <
; > If a UDF has a newer version than one you have used in previous releases, then it is likely that its syntax or features have changed. <
; > If this is the case then you may need to update your code where it makes use of the UDF.                                              <
; >                                                                                                                                       <
; > UDF Version   Command Syntax                                                                                                          <
; >                                                                                                                                       <
; > 1.4           LVCreate(x,y,w,h,WSLVStyle,EXWStyle,title,handle)                                                                       <
; > 1.1           LVSetImageList(hListView,iImageList,himl)                                                                               <
; > 1.5           LVInsertItem(hListView,iItem,text,iImage,lParam,iIndent,mask)                                                           <
; > 1.5           LVSetItem(hListView,iItem,iSubItem,text,iImage,lParam,iIndent,mask)                                                     <
; > 2.7           LVInsertColumn(hListView,iCol,iSubItem,cx,text,iImage)                                                                  <
; > 1.4           LVSetColor(hListView,component,reserved1,reserved2,rgb)                                                                 <
; > 1.0           LVGetStyle(hListView)                                                                                                   <
; > 1.0           LVSetStyle(hListView,style)                                                                                             <
; > 1.0           LVGetExtendedStyle(hListView)                                                                                           <
; > 1.0           LVSetExtendedStyle(hListView,mask,EXstyle)                                                                              <
; > 1.0           LVGetItemCount(hListView)                                                                                               <
; > 1.0           LVGetSelectedCount(hListView)                                                                                           <
; > 1.0           LVGetSelectionMark(hListView)                                                                                           <
; > 1.0           LVGetItemText(hListView,iItem,iSubItem)                                                                                 <
; > 1.0           LVDeleteItem(hListView,iItem)                                                                                           <
; > 1.0           LVDeleteColumn(hListView,iCol)                                                                                          <
; > 1.1           LVGetItemState(hListView,iItem)                                                                                         <
; > 1.0           LVSetItemState(hListView,iItem,state,stateMask)                                                                         <
; > 1.0           LVFindItem(hListView,iStart,text,flags)                                                                                 <
; > 1.1           LVFindText(hListView,iStart,iEnd,iColStart,iColContinue,iColEnd,MatchCase,Text,delim)                                   <
; > 1.0           LVGetNextItem(hListView,iStart,flags)                                                                                   <
; > 1.0           LVGetTopIndex(hListView)                                                                                                <
; > 1.0           LVScroll(hListView,dx,dy)                                                                                               <
; > 1.1           LVEnsureVisible(hListView,iItem)                                                                                        <
; > 1.1           LVArrange(hListView,code)                                                                                               <
; > 1.1           LVGetHotItem(hListView)                                                                                                 <
; > 1.1           LVSetHotItem(hListView,iIndex)                                                                                          <
; > 1.1           LVItemHitTest(hListView,x,y,delim)                                                                                      <
; > 1.1           LVGetColumnCount(hListView)                                                                                             <
; > 1.1           LVGetColumnWidth(hListView,iCol)                                                                                        <
; > 1.1           LVSetColumnWidth(hListView,iCol,cx)                                                                                     <
; > 2.9           LVSetColumn(hListView,iCol,mask,frmt,cx,text,iSubItem,iImage,iOrder)                                                    <
; > 1.4           LVGetColumn(hListView,iCol,delim)                                                                                       <
; > 1.1           LVSetIconSpacing(hListView,cx,cy,delim)                                                                                 <
; > 1.3           LVSortItems(hListView,column,direction,dataflag)                                                                        <
; > 2.1           LVEditLabel(hListView,iItem)                                                                                            <
; > 2.1           LVGetEditControl(hListView)                                                                                             <
; > 2.6           LVSaveItems(hListView,LVFileName)   - experimental                                                                      <
; > 2.6           LVLoadItems(hListView,LVFileName)   - experimental                                                                      <
; >                                                                                                                                       <
; >             ....IFICantBYTE                                                                                                           <
; >                                                                                                                                       <
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVCreate : Creates a ListView control in a Window.                                                                                       ;
;v1.4 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;x         : pixels from left                                                                                                             ;
;y         : pixels from top                                                                                                              ;
;w         : width in pixels                                                                                                              ;
;h         : height in pixels                                                                                                             ;
;WSLVStyle : Style flags (for both Window and ListView basic Styles. (See API constants WS_??? and LVS_???)                               ;
;     NOTE : If WSLVStyle is an integer value then that decimal value will be passed as a bitwised OR style value for WS and LVS styles.  ;
;            However, if WSLVStyle is a string, then a simple "default" VISIBLE CHILD window will be created containing a ListView        ;
;            control with the LVS_SINGLESEL and LVS_SHOWSELALWAYS styles set and displayed in one of the following ways:                  ;
;               If WSLVStyle = "ICON" then the ListView control will be created in ICON mode. ie: it will have LVS_ICON style applied.    ;
;              *If WSLVStyle = "REPORT" then the ListView control will be created in REPORT mode. ie: it will have LVS_REPORT style set.  ;
;               If WSLVStyle = "SMALLICON" then the ListView control will have LVS_SMALLICON style applied.                               ;
;               If WSLVStyle = "LIST" then the ListView control will have LVS_LIST style applied.                                         ;
;              *If WSLVStyle is any other string, then REPORT style will be used as the default ListView style.                           ;
;EXWStyle  : Extended Window Style (See API constants WS_EX_???)                                                                          ;
;     NOTE : If EXWStyle is an integer value then that decimal value will be passed as a bitwised OR Extended Window Style value.         ;
;            However, if EXWStyle is not an integer, but a string of any kind, then a simple "default" extended window style of           ;
;            WS_EX_CLIENTEDGE will be applied to the ListView Control's window.                                                           ;
;title     : The title or name to call the new ListView window. (If WSLVStyle contained WS_CAPTION then the title would be visible)       ;
;handle    : handle to the Winbatch Dialog (returned by the Winbatch dialog procedure)                                                    ;
;                                                                                                                                         ;
;     NOTE : If you choose to pass integer values to define non "DEFAULT" styles, you should remember to include the WS_VISIBLE window    ;
;            style (decimal value 268435456) or your window will be hidden - though, of course, sometimes you might want a hidden window! ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : ListView handle if succesful , 0 otherwise                                                                                   ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVCreate(x,y,w,h,WSLVStyle,EXWStyle,title,handle)
user32=StrCat(DirWindows(1),"user32.dll")
hinst=DllHinst("")
WS_CHILD = 1073741824
   If IsInt(WSLVStyle) == @FALSE ; "DEFAULT" Window and ListView basic styles will be used if WSLVStyle is not an integer.
                                 ; ie: we will set the Window style to be a visible child with Tab focus and the ListView will be a REPORT
                                 ; (Details) style that allows single selection only and always shows the selection even when not focused.
   WS_TABSTOP = 65536
   WS_CHILD = 1073741824
   WS_VISIBLE = 268435456
   LVS_ICON = 0
   LVS_REPORT = 1
   LVS_SMALLICON = 2
   LVS_LIST = 3
   LVS_SINGLESEL = 4
   LVS_SHOWSELALWAYS = 8
   LVS_AUTOARRANGE = 256
   StylesB4LVmode = WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_SINGLESEL|LVS_SHOWSELALWAYS|LVS_AUTOARRANGE

   WSLVStyleUpper = StrUpper(WSLVStyle) ; make detection of variable NON case sensitive

     If WSLVStyleUpper <> "ICON" && WSLVStyleUpper <> "SMALLICON" && WSLVStyleUpper <> "LIST"
     WSLVStyle = StylesB4LVmode|LVS_REPORT ; Our "DEFAULT" mode - ie: REPORT style
     Else
     If WSLVStyleUpper == "ICON" Then WSLVStyle = StylesB4LVmode|LVS_ICON
     If WSLVStyleUpper == "SMALLICON" Then WSLVStyle = StylesB4LVmode|LVS_SMALLICON
     If WSLVStyleUpper == "LIST" Then WSLVStyle = StylesB4LVmode|LVS_LIST
     EndIf
   EndIf

   If IsInt(EXWStyle) == @FALSE ; "DEFAULT" Extended Window styles will be used if EXWStyle is not an integer.
   WS_EX_CLIENTEDGE  = 512
   EXWStyle = WS_EX_CLIENTEDGE
   EndIf
If WSLVStyle|WS_CHILD == WSLVStyle
hMenuq = Random(999)+9000 ; If the Window is a CHILD then make a "Random" hopefully unique child-window identifier. (in the range 9000-9999)
Else
hMenuq = 0
EndIf
Return DllCall(user32,long:"CreateWindowExA",long:EXWStyle,lpstr:"SysListView32",lpstr:title,long:WSLVStyle,long:x,long:y,long:w,long:h,long:handle,long:hMenuq,long:hinst,long:0)
; hinst is ignored by NT,2000 and XP but needed for 95,98 and ME
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSetImageList : Sets the ImageList of a ListView control.                                                                               ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;iImageList : Type of image list. This parameter can be one of the following values:                                                      ;
;             LVSIL_NORMAL = 0    Image list with large icons.                                                                            ;
;             LVSIL_SMALL = 1     Image list with small icons. - Used for Report and List style views                                     ;
;             LVSIL_STATE = 2     Image list with state images. - State images are secondary icons (eg: the checkbox)                     ;
;himl       : Handle of the image list to assign.                                                                                         ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetImageList(hListView,iImageList,himl)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SETIMAGELIST = LVM_FIRST + 3
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETIMAGELIST,long:iImageList,long:himl)
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;LVInsertItem : Insert a new item in a ListView control.                                                                                                      ;
;               Note: YOU CANNOT USE LVINSERTITEM to INSERT SUBITEMS                                                                                          ;
;                      use LvSetItem to insert subitem values                                                                                                 ;
;v1.5 by ....IFICantBYTE                                                                                                                                      ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;hListView    : ListView handle returned by LVCreate()                                                                                                        ;
;iItem        : index of item where the new item will be inserted                                                                                             ;
;text         : item text                                                                                                                                     ;
;iImage       : index of the icon to use in an associated ImageList *see note                                                                                 ;
;lParam       : a 32-bit value to associate with the item                                                                                                     ;
;iIndent      : number of icon widths to indent the item by                                                                                                   ;
;mask         : to use defaults (all above), just pass a negative number or a non numeric value, otherwise use ORed LVIF_?????? WinAPI values to be specific. ;
;              eg: 1 = Text only , 1|2 = Text and Image , 0 or "DEFAULT" would use default mask of 1|2|4|16 which is all UDF values TEXT|IMAGE|PARAM|INDENT   ;
;            * it seems that if an imagelist has been assigned to the LV then each item will have a default ZERO value for an icon even if the mask is set    ;
;              to text only (1) ... therefore if an imagelist is used, and an icon is unwanted, set the mask to include image info and set iImage to -1       ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;Returns      : Returns the index of the new item if successful, or -1 otherwise.                                                                             ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVInsertItem(hListView,iItem,text,iImage,lParam,iIndent,mask)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_INSERTITEMA = LVM_FIRST + 7
If IsInt(mask) == @FALSE || mask < 0 Then mask = 1|2|4|16 ; If mask is not an integer or is less than 0 then use the "Defaults" - ie. TEXT|IMAGE|PARAM|INDENT

TextBuf=BinaryAlloc(StrLen(text)+1)
   BinaryPokeStr(TextBuf,0,text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;-----Make LVItem structure----------------------------------------------------
   LVITEM=BinaryAlloc(40)          ; Create buffer for structure
   BinaryPoke4(LVITEM,0,mask)      ; mask (TEXT|IMAGE|PARAM|INDENT ...see LVIF_?????? constants for Windows API) // sets the active attributes of this data structure
   BinaryPoke4(LVITEM,4,iItem)     ; iItem  // Zero-based index of the item to which this structure refers
   ;BinaryPoke4(LVITEM,8,0)        ; iSubitem  // YOU CANNOT USE INSERTITEM to INSERT SUBITEMS - the value must be 0 - (use SETITEM to insert subitem values)
   ;BinaryPoke4(LVITEM,12,0)       ; state   // Specifies the current state of the item  - decided to omit this option from LVInsertItem to keep it more simple - use LVSetItemState
   ;BinaryPoke4(LVITEM,16,0)       ; stateMask  // Specifies the bits of the state member that are valid - decided to omit - see above state comment
   BinaryPoke4(LVITEM,20,TextAd)   ; pszText  // Pointer to a buffer that receives the item text
   ;BinaryPoke4(LVITEM,24,255)     ; cchTextMax // Number of characters in the buffer pointed to by pszText. Only used when the structure receives item attributes.
   BinaryPoke4(LVITEM,28,iImage)   ; iImage  // index of the list view item's icon.
   BinaryPoke4(LVITEM,32,lParam)   ; LParam  // 32-bit value to associate with item - this can be a value your application might want to associate for some kind of custom use
   BinaryPoke4(LVITEM,36,iIndent)  ; iIndent  // Number of icon widths to indent the ITEM by (only works for Items not SubItems)
   ;------------------------------------------------------------------------------

ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_INSERTITEMA,long:0,lpbinary:LVITEM)
BinaryFree(LVITEM)
BinaryFree(TextBuf)
Return ret
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------------------------------------------------------------;
;LVSetItem : Sets some or all of an EXISTING ListView item's attributes - including SubItems                                                               ;
;            ( Use this AFTER creating an item with the LVInsertItem UDF )                                                                                 ;
;v1.5 by IFICantBYTE                                                                                                                                       ;
;----------------------------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : ListView handle returned by LVCreate()                                                                                                      ;
;iItem       : index of the existing item where the data will be inserted                                                                                  ;
;iSubitem    : One-based index of the subitem to which this structure refers, or zero if this structure refers to an item rather than a subitem.           ;
;text        : item text                                                                                                                                   ;
;iImage      : index of the icon to use in an associated ImageList                                                                                         ;
;lParam      : a 32-bit value to associate with the item - not valid for Subitems                                                                          ;
;iIndent     : number of icon widths to indent the item by - not valid for SubItems                                                                        ;
;mask        : to use defaults (all above), just pass a negative or a non-numeric value, otherwise use ORed LVIF_?????? WinAPI values to be specific.      ;
;              eg: 1 = Text only , 1|2 = Text and Image , -1 or "ALL" would use default mask of 1|2|4|16 for ITEMS                                         ;
;                  which are values for TEXT|IMAGE|PARAM|INDENT ... BUT it would use only 1|2 for SUBITEMS as any other values are not valid.              ;
;                  Passing a mask that contains non-valid bits (such as 1|2|4 for a SUBITEM) will return an error (0) from the UDF.                        ;
;----------------------------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : Returns TRUE (1) if successful, or FALSE (0) otherwise.                                                                                     ;
;----------------------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetItem(hListView,iItem,iSubItem,text,iImage,lParam,iIndent,mask)
user32=StrCat(DirWindows(1),"user32.dll")

LVM_FIRST = 4096
LVM_SETITEMA = LVM_FIRST + 6
;If mask is any string other than a specific mask value (an integer) or if it is is a negative number then use one of the following "Defaults"
If IsInt(mask) == @FALSE || mask < 0
   If iSubItem <> 0
      mask = 1|2  ; For SUBITEMS - only 1 and 2 (Text and Image) are valid
   Else
      mask = 1|2|4|16 ;  For ITEMS set the valid mask bits for TEXT|IMAGE|PARAM|INDENT
   EndIf
EndIf

 TextBuf=BinaryAlloc(StrLen(text)+1)
   BinaryPokeStr(TextBuf,0,text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;-----Make LVITEM structure----------------------------------------------------
   LVITEM=BinaryAlloc(40)          ; Create buffer for structure
   BinaryPoke4(LVITEM,0,mask)      ; mask
   BinaryPoke4(LVITEM,4,iItem)     ; iItem
   BinaryPoke4(LVITEM,8,iSubItem)  ; iSubitem
   ;BinaryPoke4(LVITEM,12,0)       ; state - not valid for SubItems - decided to omit this option from LVSetItem to keep it more simple - use LVSetItemState
   ;BinaryPoke4(LVITEM,16,0)       ; stateMask - see above
   BinaryPoke4(LVITEM,20,TextAd)   ; pszText
   ;BinaryPoke4(LVITEM,24,255)     ; cchTextMax ~ not required to set text - looks for NULL in buffer to mark end of string
   BinaryPoke4(LVITEM,28,iImage)   ; iImage
   BinaryPoke4(LVITEM,32,lParam)   ; LParam  ~ not valid for SubItems
   BinaryPoke4(LVITEM,36,iIndent)  ; iIndent ~ not valid for SubItems
   ;-------------------------------------------------------------------------------

ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETITEMA,long:0,lpbinary:LVITEM)
BinaryFree(LVITEM)
BinaryFree(TextBuf)
Return ret
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------;
;LVInsertColumn : Insert a new Column in a ListView control.                                ;
;v2.7 (bugfix of 1.4) by IFICantBYTE (2011)                                                 ;
;-------------------------------------------------------------------------------------------;
;hListView      : ListView handle returned by LVCreate()                                    ;
;iCol           : index of of the new column (zero based left to right)                     ;
;iSubItem       : index of subitem associated with the column                               ;
;cx             : width of the column in pixels                                             ;
;text           : column header text                                                        ;
;iImage         : index of the icon to use in an associated ImageList or negative for none. ;
;                  - you will get display problems if you specify one but don't associate a ;
;                    valid imagelist, so make it -1 if you don't have one.                  ;
;-------------------------------------------------------------------------------------------;
;Returns        : Returns the index of the new column if successful, or -1 otherwise        ;
;-------------------------------------------------------------------------------------------;
#DefineFunction LVInsertColumn(hListView,iCol,iSubItem,cx,text,iImage)
user32=StrCat(DirWindows(1),"user32.dll")

LVM_FIRST = 4096  ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_INSERTCOLUMNA = LVM_FIRST + 27
iOrder = iCol ;Zero-based column offset. Column offset is in left-to-right order. - we are setting this to be the same as iCol - but it doesn't have to be - can get confusing though
mask = 1|2|4|8|32
frmt = 0
If iImage >= 0 ;if the column header has an icon then include the iImage in the mask and the correct formating - if this is not
   mask = mask|16
   frmt = frmt|2048|4096|32768
EndIf
TextBuf=BinaryAlloc(StrLen(text)+1)
   BinaryPokeStr(TextBuf,0,text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;----- Make Column structure -------------------------------------------------------
   LVCOLUMN=BinaryAlloc(32)                 ; Create buffer for structure
   BinaryPoke4(LVCOLUMN,0,mask)    ; mask (see LVCF_?????? Windows API constants)
   BinaryPoke4(LVCOLUMN,4,frmt)    ; frmt (see LVCFMT_???? Windows API constants and comment below)
   ;Note: If a column is added to a list-view control with index 0 (the leftmost column), it is always LVCFMT_LEFT.
   ;Setting other flags on column 0 does not override that alignment. Therefore if you keep inserting columns with index 0,
   ;the text in all columns are left-aligned. If you want the first column to be right-aligned or centered you can make a dummy column,
   ;then insert one or more columns with index 1 or higher and specify the alignment you require. Finally delete the dummy column.
   BinaryPoke4(LVCOLUMN,8,cx)               ; cx
   BinaryPoke4(LVCOLUMN,12,TextAd)          ; pszText // address of pointer to text string for column header name
   BinaryPoke4(LVCOLUMN,16,255)             ; cchTextMax
   BinaryPoke4(LVCOLUMN,20,iSubItem)        ; iSubItem
   BinaryPoke4(LVCOLUMN,24,iImage)          ; iImage  // Zero-based index of an image within the image list to put in the column
   BinaryPoke4(LVCOLUMN,28,iOrder)          ; iOrder  // Zero-based column offset. Column offset is in left-to-right order. - we are setting this to be the same as iCol - but it doesn't have to be - can get confusing though
   ;-----------------------------------------------------------------------------------

 ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_INSERTCOLUMNA,long:iCol,lpbinary:LVCOLUMN)
 BinaryFree(LVCOLUMN)
 BinaryFree(TextBuf)
 Return ret
 #EndFunction
;##########################################################################################################################################


;--------------------------------------------------------------------------------------------------------------;
;LVSetColor : Set the colours used in a ListView control                                                       ;
;v1.4 by IFICantBYTE (2004)                                                                                    ;
;--------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                  ;
;component  : value to select the type of ListView component to change the colour of...                        ;
;             eg: 0 = The Background colour of the ListView control (default)                                  ;
;                     NOTE: Microsoft say: "List-view controls with background colors redraw themselves        ;
;                           significantly faster than those without background colors"                         ;
;                 1 = The Background colour of all item text in a ListView control                             ;
;                 2 = The Forground colour of all item text in a ListView control                              ;
;                 NOTE:  other values are not valid in v1.0 of this UDF.                                       ;
;                        future versions may support other components such as individual items or columns.     ;
;reserved1  : not used in v1.0 of this UDF - reserved for future versions - just put in a 0 (zero) value       ;
;reserved2  : not used in v1.0 of this UDF - reserved for future versions - just put in a 0 (zero) value       ;
;rgb        : "RED|GREEN|BLUE" value (use 0 to 255 for each seperated by | as a text string - ie: in quotes)   ;
;             or "CLR_NONE" for no defined colour.                                                             ;
;--------------------------------------------------------------------------------------------------------------;
;Returns    : 1 (TRUE) if successful or 0 (FALSE) otherwise                                                    ;
;--------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetColor(hListView,component,reserved1,reserved2,rgb)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SETBKCOLOR = LVM_FIRST + 1
LVM_SETTEXTCOLOR = LVM_FIRST + 36
LVM_SETTEXTBKCOLOR = LVM_FIRST + 38
LVM_REDRAWITEMS = LVM_FIRST + 21
LVM_SETOUTLINECOLOR = LVM_FIRST + 177
If rgb == "CLR_NONE"
COLOUR = 4294967295 ; Windows API value (CLR_NONE) to CLEAR ie: no defined colour (couldn't work out if this was working properly during testing in v1.0)
Else
r = ItemExtract(1,rgb,"|")
g = ItemExtract(2,rgb,"|")
b = ItemExtract(3,rgb,"|")
COLOUR = b*256*256 + g*256 + r
EndIf

Switch component
    Case 1 ; Background of All item text
            ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETTEXTBKCOLOR,long:0,long:COLOUR)
            Break
    Case 2 ; Forground of All item text
            ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETTEXTCOLOR,long:0,long:COLOUR)
            Break
    Case 3 ; Sets the color of the border of a list-view control if the LVS_EX_BORDERSELECT extended window style is set and Comclt32.dll is version 6.0.+ and active - manifest may be required - not tested
            ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETOUTLINECOLOR,long:0,long:COLOUR)
            Break

    Case component  ; Background - the default value if 0 or any non-valid integer is entered.
            ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETBKCOLOR,long:0,long:COLOUR)
            RDW_FRAME = 1024 ; Causes any part of the nonclient area of the window that intersects the update region to receive a WM_NCPAINT message. (Might need for modal windows over the top when ours redraws? - but not implemented in v1.0)
            RDW_INVALIDATE = 1 ;Invalidates lprcUpdate or hrgnUpdate (only one may be non-NULL). If both are NULL, the entire window is invalidated (This is what we will do with zero in each).
            RDW_ERASE = 4 ; Causes the window to receive a WM_ERASEBKGND message when the window is repainted
            DllCall(user32,long:"RedrawWindow",long:hListView,long:0,long:0,long:RDW_ERASE|RDW_INVALIDATE) ; The RedrawWindow function updates the specified rectangle or region in a window's client area.
                                                                                                           ; We have told it that our entire window is invalid now and needs redrawing - this is so our new background colour is drawn.
            Break
EndSwitch
iFirst = 0 ; Index of first item to be redrawn
iLast = 9999 ; Index of last item to be redrawn - (by putting a large number in, we can redraw the whole list without having to know how many items are really there)
DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_REDRAWITEMS,long:iFirst,long:iLast) ; The specified items are not actually redrawn until the ListView window receives a WM_PAINT message to repaint by the OS.
Return ret
#EndFunction
;##########################################################################################################################################


;--------------------------------------------------------------------------------------------------------------------------------------------;
;LVGetStyle : Get the Style of the ListView control                                                                                          ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                                          ;
;--------------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : ListView handle                                                                                                               ;
;--------------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : Returns the basic style value of the ListView control (a combination of LVS_??? and WS_??? values See Windows API constants)  ;
;--------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetStyle(hListView)
user32 = StrCat(DirWindows(1),"user32.dll")
GWL_STYLE = -16 ; offset for the Window Style value
ret = DllCall(user32,long:"GetWindowLongA",long:hListView,long:GWL_STYLE)
Return ret
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;LVSetStyle : Set the Style of the ListView control                                                                                                           ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                                                           ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : ListView handle                                                                                                                                ;
;style       : ListView style (a combination of LVS_??? and WS_??? values See Windows API constants)                                                          ;
;       NOTE : It is usually wise to use the LVGetStyle command first, and then modify the returned value to keep any other style settings intact             ;
;              Some style changes wont appear to take effect and need to be done a different way by sending a STYLECHANGED notification to the Window         ;
;              which is not specific to ListView controls - it is used by all Windows and is not directly supported by this ListView UDF command in v1.0      ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : If the function succeeds, the return value is the previous value. If the function fails, the return value is zero. (See Windows API constants) ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetStyle(hListView,style)
user32 = StrCat(DirWindows(1),"user32.dll")
GWL_STYLE = -16 ; offset for the Window Style value
ret = DllCall(user32,long:"SetWindowLongA",long:hListView,long:GWL_STYLE,long:style)
Return ret
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------;
;LVGetExtendedStyle : Get the Extended ListView Style of the hListView control                       ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                  ;
;----------------------------------------------------------------------------------------------------;
;hListView          : ListView handle                                                                ;
;----------------------------------------------------------------------------------------------------;
;Returns            : Returns a value that contains the Extended styles (See Windows API constants)  ;
;----------------------------------------------------------------------------------------------------;
#DefineFunction LVGetExtendedStyle(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETEXTENDEDLISTVIEWSTYLE,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;---------------------------------------------------------------------------------------------------;
;LVSetExtendedStyle : Apply any Extended ListView Style to the hListView handle passed              ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                 ;
;---------------------------------------------------------------------------------------------------;
;hListView   : ListView handle                                                                      ;
;mask        : style mask - 0 for ALL styles OR make it the style(s) value you ONLY want to change  ;
;ExStyle     : Extended ListView style(s)                                                           ;
;              if more than one, OR them eg: 8|32|128  (See Windows API constants)                  ;
;---------------------------------------------------------------------------------------------------;
;Returns     : Returns a value that contains the previous Extended styles                           ;
;---------------------------------------------------------------------------------------------------;
#DefineFunction LVSetExtendedStyle(hListView,mask,EXstyle)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETEXTENDEDLISTVIEWSTYLE,long:mask,long:EXstyle) ;note: the second last value is a style mask - if not 0 (ALL styles) then make it the style value you ONLY want to change
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------;
;LVGetItemCount : Retrieves the number of items in a ListView control.    ;
;v1.0 by IFICantBYTE (24 July 2003)                                       ;
;-------------------------------------------------------------------------;
;hListView : ListView handle                                              ;
;-------------------------------------------------------------------------;
;Returns : the number of items                                            ;
;-------------------------------------------------------------------------;
#DefineFunction LVGetItemCount(hListView)
user32=StrCat(DirWindows(1),"user32.dll")

LVM_FIRST = 4096  ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_GETITEMCOUNT = LVM_FIRST + 4
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMCOUNT,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------------;
;LVGetSelectedCount : Retrieves a count of the number of selected items in a ListView control.    ;
;v1.0 by IFICantBYTE (24 July 2003)                                                               ;
;-------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                      ;
;-------------------------------------------------------------------------------------------------;
;Returns : The number of selected items.                                                          ;
;-------------------------------------------------------------------------------------------------;
#DefineFunction LVGetSelectedCount(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETSELECTEDCOUNT = LVM_FIRST + 50
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETSELECTEDCOUNT,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;--------------------------------------------------------------------------------------------------------------------------;
;LVGetSelectionMark : Returns the zero-based selection mark, or -1 if there is no selection mark in a ListView control.    ;
;                     (From MS site: "The selection mark is the item index from which a multiple selection starts")        ;
;              NOTE : I have found this to be inconsistant in what index it returns except ironically when only one item   ;
;                     is selected. (or when the shift key is used for consecutive multiple selections) But in all cases,   ;
;                     it seems to be more like a "item just clicked" function. IFICantBYTE (29 July 2003)                  ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                        ;
;--------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                               ;
;--------------------------------------------------------------------------------------------------------------------------;
;Returns : The zero-based selection mark (Item index), or -1 if there is none selected.                                    ;
;--------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetSelectionMark(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETSELECTIONMARK = LVM_FIRST + 66
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETSELECTIONMARK,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------;
;LVGetItemText : Returns the text of an Item or its SubItem.                                ;
;v1.0 by IFICantBYTE (24 July 2003)                                                         ;
;-------------------------------------------------------------------------------------------;
;hListView     : ListView handle                                                            ;
;iItem         : The ListView items index number you want to return the text from.          ;
;iSubItem      : The SubItem you want to return the text from.                              ;
;                ( To retrieve the item text, set iSubItem to zero )                        ;
;                ( To retrieve the text of a subitem, set iSubItem to the subitem's index ) ;
;-------------------------------------------------------------------------------------------;
;Returns       : The Text from the Item or one of its Subitems                              ;
;-------------------------------------------------------------------------------------------;
#DefineFunction LVGetItemText(hListView,iItem,iSubItem)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETITEMTEXTA = LVM_FIRST + 45
  bufsize = 255 ; you can make this value bigger if your item's text is very long, or rewrite this UDF in a more clever way to use the TextStrLen variable below
  TextBuf=BinaryAlloc(bufsize + 1)
  TextAd=IntControl(42,TextBuf,0,0,0)

   ;-----Make LVITEM structure----------------------------------------------------
   LVITEM=BinaryAlloc(36)          ; Create buffer for structure
   BinaryPoke4(LVITEM,0,1)         ; mask
   BinaryPoke4(LVITEM,4,iItem)     ; iItem
   BinaryPoke4(LVITEM,8,iSubItem)  ; iSubitem
  ;BinaryPoke4(LVITEM,12,0)        ; state
  ;BinaryPoke4(LVITEM,16,0)        ; stateMask
   BinaryPoke4(LVITEM,20,TextAd)   ; pszText
   BinaryPoke4(LVITEM,24,255)      ; cchTextMax
  ;BinaryPoke4(LVITEM,28,0)        ; iImage
  ;BinaryPoke4(LVITEM,32,0)        ; LParam
   ;-------------------------------------------------------------------------------
TextStrLen = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMTEXTA,long:iItem,lpbinary:LVITEM) ; this fills the TextBuffer we made and returns the string length (though not actually used by us here)
Message("StrLen",textstrlen)
BinaryEodSet(TextBuf,bufsize + 1)
itemtext=BinaryPeekStr(TextBuf,0,bufsize) ;selected item
BinaryFree(LVITEM)
BinaryFree(TextBuf)
Return itemtext
#EndFunction
;##########################################################################################################################################


;--------------------------------------------------------------------------------------------;
;LVDeleteItem : Deletes a single item or all items in a ListView control                     ;
;v1.0 by IFICantBYTE (24 July 2003)                                                          ;
;--------------------------------------------------------------------------------------------;
;hListView    : ListView handle                                                              ;
;iItem        : Index of the Item you want to delete OR -1 if you want to delete ALL items   ;
;--------------------------------------------------------------------------------------------;
;Returns      : Returns TRUE (1) if successful, or FALSE (0) otherwise.                      ;
;--------------------------------------------------------------------------------------------;
#DefineFunction LVDeleteItem(hListView,iItem)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_DELETEITEM = LVM_FIRST + 8
LVM_DELETEALLITEMS = LVM_FIRST + 9
If iItem == -1
iItem = 0
LVM_DELETETYPE = LVM_DELETEALLITEMS
Else
LVM_DELETETYPE = LVM_DELETEITEM
EndIf
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_DELETETYPE,long:iItem,long:0)
#EndFunction
;##########################################################################################################################################


;--------------------------------------------------------------------------;
;LVDeleteColumn : Deletes a column in a ListView control                   ;
;v1.0 by IFICantBYTE (24 July 2003)                                        ;
;--------------------------------------------------------------------------;
;hListView      : ListView handle                                          ;
;iCol           : Index of column (zero based left to right)               ;
;       NOTE: YOU CAN NOT DELETE COLUMN 0 (zero) ie: the first column      ;
;--------------------------------------------------------------------------;
;Returns        : Returns TRUE (1) if successful, or FALSE (0) otherwise.  ;
;--------------------------------------------------------------------------;
#DefineFunction LVDeleteColumn(hListView,iCol)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_DELETECOLUMN = LVM_FIRST + 28
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_DELETECOLUMN,long:iCol,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------;
;LVGetItemState : Retrieves the state of a ListView item                                                    ;
;v1.1 by IFICantBYTE (26 July 2003)                                                                         ;
;-----------------------------------------------------------------------------------------------------------;
;hListView      : ListView handle                                                                           ;
;iItem          : Index of the Item                                                                         ;
;-----------------------------------------------------------------------------------------------------------;
;Returns        : BitMask value of the Item's state. (see LVIS Windows API values)                          ;
;                 eg: it will return 1 if the item has the FOCUS                                            ;
;                     it will return 2 if the item is SELECTED                                              ;
;                     it will return 3 if the item has the FOCUS AND it is SELECTED ( 1 | 2 = 3)            ;
;                     Note: LVIS_OVERLAYMASK and LVIS_STATEIMAGEMASK actually return the                    ;
;                           One based item's overlay or state image index in the associated imagelist.      ;
;                           (Bits 12 through 15 specify the one-based index of an image in the control's    ;
;                            state image list. 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)                                                                ;
; - Note: you could set the MASK to be any single or combination of the LVIS values so it wouldn't return   ;
;         the values of any other states, and would return just a 0 if the one(s) in question were not set. ;
;         (except for OVERLAYMASK and STATEIMAGEMASK - they return different info - see above)              ;
;         However, it is probably more useful to get everything in one go and then just use a logical OR    ;
;         on the result to determine the status of a state....                                              ;
;   - eg: the following would see if an item was selected or not:                                           ;
;         StateOfItem = LVGetItemState(hListView,iItem)                                                     ;
;         If StateOfItem == (StateOfItem|2)                                                                 ;
;            Message(StateOfItem,"Item IS Selected")                                                        ;
;         Else                                                                                              ;
;            Message(StateOfItem,"Item is NOT selected")                                                    ;
;         EndIf                                                                                             ;
;-----------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetItemState(hListView,iItem)
   user32=StrCat(DirWindows(1),"user32.dll")
   LVM_FIRST = 4096
   LVM_GETITEMSTATE = LVM_FIRST + 44
   LVIS_CUT = 4
   LVIS_DROPHILITED = 8
   LVIS_FOCUSED = 1
   LVIS_SELECTED = 2
   LVIS_OVERLAYMASK = 3840 ;returns imagelist index bits
   LVIS_STATEIMAGEMASK = 61440 ;returns imagelist index bits - seems to be used by checkboxes ... 4096 = checked on (for standard tick - haven't tested on non-standard like grey 3 state kind yet)
   MASK = LVIS_CUT | LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED | LVIS_OVERLAYMASK | LVIS_STATEIMAGEMASK  ; tell it to return any of these values if they are set on the item in question
   Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMSTATE,long:iItem,long:MASK)
#EndFunction
;##########################################################################################################################################


;-------------------------------------------------------------------------------------------------------------------------------------------------------;
;LVSetItemState : Changes the state of an item or all items in a ListView control.                                                                      ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                                                     ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------;
;hListView      : ListView handle                                                                                                                       ;
;iItem          : The ListView items index number you want to set the state of OR -1 FOR ALL ITEMS.                                                     ;
;state          : The LVIS_????? state bits value(s)  (see below)                                                                                       ;
;stateMask      : specifies which state bits to change   (see below)                                                                                    ;
;                                                                                                                                                       ;
;          NOTE : The stateMask member specifies which state bits to change, and the state member contains the new values for those bits.               ;
;                eg: to set item 4 to be selected and leave all it's other state properties alone you would use...                                      ;
;                         LVSetItemState(yourLVhandle,4,2,2)  // where item = 4 , state = 2 (SELECTED), stateMask also = 2 (SELECTED BIT)               ;
;                                                                                                                                                       ;
;                    to set the focus to item 4 and leave it's other state properties alone you would use...                                            ;
;                         LVSetItemState(yourLVhandle,4,1,1)  // where item = 4 , state = 1 (FOCUSED), stateMask also = 1 (FOCUSED BIT)                 ;
;                                                                                                                                                       ;
;                    to do both of the above commands in one go, we could have added the FOCUSED and SELECTED state bit values together and used...     ;
;                         LVSetItemState(yourLVhandle,4,3,3)  // where item = 4 , state = 3 (2 + 1), stateMask also = 3 (FOCUSED + SELECTED BITs)       ;
;                                                                NOTE: It is really a bitwise OR of the values we should do ie: 1|2 will still equal 3  ;
;                    You might be wondering what the mask is for - it's always the same as the state value - WELL, what if we only wanted to change     ;
;                    a particular state, but we didn't want to change any others, and we didn't know what states the item had set or unset already?     ;
;                    This is where we need the mask - eg: to deselect item 4 now, but not alter it's focus bit regardless of the current state, use...  ;
;                         LVSetItemState(yourLVhandle,4,0,2) // where item = 4 , state = 0 (CLEAR), stateMask = 2 (apply to the SELECTED BIT only)      ;
;                                                                                                                                                       ;
;     ALSO NOTE : Only 1 item at a time can be selected if your ListView has the LVS_SINGLESEL style applied to it and only 1 item at a time can have   ;
;                 the focus in any type of ListView.                                                                                                    ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------;
;Returns       : returns TRUE (1) if successful or FALSE (0) otherwise.                                                                                 ;
;-------------------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetItemState(hListView,iItem,state,stateMask)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SETITEMSTATE = LVM_FIRST + 43
LVIS_CUT = 4
LVIS_DROPHILITED = 8
LVIS_FOCUSED = 1
LVIS_SELECTED = 2
LVIS_OVERLAYMASK = 3840
LVIS_STATEIMAGEMASK = 61440

   ;-----Make LVITEM structure----------------------------------------------------
   LVITEM=BinaryAlloc(36)          ; Create buffer for structure
   BinaryPoke4(LVITEM,0,8)         ; mask  \\ 8 = LVIF_STATE
   BinaryPoke4(LVITEM,4,iItem)     ; iItem
  ;BinaryPoke4(LVITEM,8,0)         ; iSubitem
   BinaryPoke4(LVITEM,12,state)    ; state
   BinaryPoke4(LVITEM,16,stateMask); stateMask
  ;BinaryPoke4(LVITEM,20,0)        ; pszText
  ;BinaryPoke4(LVITEM,24,0)        ; cchTextMax
  ;BinaryPoke4(LVITEM,28,0)        ; iImage
  ;BinaryPoke4(LVITEM,32,0)        ; LParam
   ;-------------------------------------------------------------------------------
ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETITEMSTATE,long:iItem,lpbinary:LVITEM)
BinaryFree(LVITEM)
Return ret
#EndFunction
;##########################################################################################################################################


;---------------------------------------------------------------------------------------------;
;LVFindItem  : Find an Item in a ListView control.                                            ;
;v1.0 by IFICantBYTE (24 July 2003) **** See NOTE below **** ....IFICantBYTE 2004             ;
;---------------------------------------------------------------------------------------------;
;hListView   : ListView handle returned by LVCreate()                                         ;
;iStart      : Index of the item to begin the search with or -1 to start from the beginning.  ;
;              (THE SPECIFIED ITEM IS ITSELF EXCLUDED FROM THE SEARCH)                        ;
;text        : Text to search for (it is NOT case sensitive)                                  ;
;flags       : flag indicating the type of search...                                          ;
;              use 2 for an exact match, 8 for a partial match.                               ;
;              (Other values are not used by my ListView v1.0 UDFs. But Param could be with a ;
;               fairly easy tweak though. IFICantBYTE 24 July 2003                            ;
;       NOTE : Only the text in the ITEM is searched NOT the subItems                         ;
;              **** See new function LVFindText added in v1.1 ListView UDFs                   ;
;---------------------------------------------------------------------------------------------;
;Returns     : Returns the index of the item if successful, or -1 otherwise.                  ;
;---------------------------------------------------------------------------------------------;
#DefineFunction LVFindItem(hListView,iStart,text,flags)
user32=StrCat(DirWindows(1),"user32.dll")

LVM_FIRST = 4096  ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_FINDITEMA = LVM_FIRST + 13

TextBuf=BinaryAlloc(StrLen(text)+1)
   BinaryPokeStr(TextBuf,0,text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;----- Make LVFINDINFO structure ---------------------------------------------------------------------------------
   LVFINDINFO=BinaryAlloc(20)        ; Create buffer for structure
   BinaryPoke4(LVFINDINFO,0,flags)   ; flags       // 2 = LVFI_STRING, 8 = LVFI_PARTIAL, 1 = LVFI_PARAM (see LVFI_????? Windows API constants for others)
   BinaryPoke4(LVFINDINFO,4,TextAd)  ; psz         // 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.
  ;BinaryPoke4(LVFINDINFO,8,0)       ; lParam      // 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.
  ;BinaryPoke4(LVFINDINFO,12,0)      ; pt          // POINT structure with the initial search position. It is valid only if LVFI_NEARESTXY is set in the flags member
  ;BinaryPoke4(LVFINDINFO,16,0)      ; vkDirection // Virtual key code that specifies the direction to search. It is valid only if LVFI_NEARESTXY is set in the flags member
   ;-----------------------------------------------------------------------------------------------------------------

ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_FINDITEMA,long:iStart,lpbinary:LVFINDINFO)
BinaryFree(LVFINDINFO)
BinaryFree(TextBuf)
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVFindText : Searches a range of Items and/or SubItems for a sub-string and returns a delimited string of the first                      ;
;             Item & Column (SubIitem) Index location that the sub-string is found in.                                                    ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView    : ListView handle                                                                                                           ;
;iStart       : The ListView item or sub-item's index number to start the search from. (inclusive)(zero based)                            ;
;iEnd         : The ListView item or subitem's index number to end the search on. (inclusive)                                             ;
;        NOTE : If required, you can use the LVGetItemCount function to obtain the total number of items first.                           ;
;iColStart    : The ListView column's index number (only report style for SubItems) to start the search from. (inclusive) (zero based)    ;
;iColContinue : The ListView column to start the FIRST (iStart) item's search from - will override iColStart for the first Item only.     ;
;        NOTE : If a previous LVFindText found a match to a sub-string in an Item that contained SubItems, and you want to continue the   ;
;               search from the next SubItem (Column) of the SAME Item, then you can set iStart to the returned parent item's index and   ;
;               set iColContinue to the next Column index after the returned one. This will stop the sub-string from being found again in ;
;               the same SubItem but let it search the rest of that Item's SubItems and then continue searching the full iColStart to     ;
;               iColEnd range in any following Items.                                                                                     ;
;iColEnd      : The ListView column's index number you want to end the search on. (inclusive)(zero based - zero is the item in report)    ;
;        NOTE : If required, you can use the LVGetColumnCount function to obtain the total number of columns (SubItems) first.            ;
;MatchCase    : Use 0 (zero) to ignore case sensitivity, anything else uses a case sensitive search.                                      ;
;Text         : The sub-string to be searched for                                                                                         ;
;delim        : The delimiter you want to use between the returned Item and Column values - eg: "," or @TAB or @CRLF or " " (space)       ;
;                                                                                                                                         ;
;        NOTE : There is no "built-in function" in the ListView to search for true sub-strings or through subitems. (see LVFindItem)      ;
;               So that is why this was created. BUT this Function can be a bit slow if there are many strings to search recursivly       ;
;               through, and even slower on older PCs. The best idea to keep it quick is to only define a small range to search through   ;
;               if you can. ie: restrict it to a single column to search in or start/end the search around the index area you think the   ;
;               string might be, or both if possible. Note the use of the iColContinue value in multiple searches.                        ;
;               In it's present form, the low/high index values for items and columns will be swapped if they are backwards, and so the   ;
;               search order will still be ascending from the low to the high value - basically, there is no backwards searching.         ;
;               There is also no checking of the index values to see if they fall outside the range of the items or columns, so you       ;
;               should pass it valid values or you will either miss totally and get -1 or get the result but be waiting longer than was   ;
;               necessary while it searches null values. Use the LVGetItemCount and LVGetColumnCount functions first to help you define a ;
;               range to search. ....IFICantBYTE (2004)                                                                                   ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns      : Returns a delimited string containing two values.  eg: 34,8  - each value represents the following:                       ;
;               First value  : is the index of the matching parent item or -1 if the string was not found at all.                         ;
;               Second value : is the index of the matching column (SubItem) or -1 if the string was not found at all.                    ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVFindText(hListView,iStart,iEnd,iColStart,iColContinue,iColEnd,MatchCase,Text,delim)
user32=StrCat(DirWindows(1),"user32.dll")
;user32=DllLoad(strcat(dirwindows(1),"user32.dll")) ; loading the DLL didn't seem to make any difference to speed

LVM_FIRST = 4096
LVM_GETITEMTEXTA = LVM_FIRST + 45
; Swap the Start and End values around if they are not defined properly
If iStart > iEnd
   iTemp = iStart
   iStart = iEnd
   iEnd = iTemp
EndIf
If iColStart > iColEnd
   iTemp = iColStart
   iColStart = iColEnd
   iColEnd = iTemp
EndIf

FoundIn = StrCat(-1,delim,-1)

bufsize = 255 ; you can make this value bigger if your item's text is very long
TextBuf=BinaryAlloc(bufsize + 1)
TextAd=IntControl(42,TextBuf,0,0,0)
LVITEM=BinaryAlloc(36)          ; Create buffer for structure
StartItem = iStart
While (iStart <= iEnd)
   iItem = iStart
   If iStart == StartItem ; If it's the first item searched
      iSubItem = iColContinue
   Else
      iSubItem = iColStart
   EndIf
   While (iSubitem <= iColEnd)
      BinaryPoke4(LVITEM,0,1)         ; mask
      BinaryPoke4(LVITEM,4,iItem)     ; iItem
      BinaryPoke4(LVITEM,8,iSubItem)  ; iSubitem
      ;BinaryPoke4(LVITEM,12,0)        ; state
      ;BinaryPoke4(LVITEM,16,0)        ; stateMask
      BinaryPoke4(LVITEM,20,TextAd)   ; pszText
      BinaryPoke4(LVITEM,24,255)      ; cchTextMax
      ;BinaryPoke4(LVITEM,28,0)        ; iImage
      ;BinaryPoke4(LVITEM,32,0)        ; LParam
      ;-------------------------------------------------------------------------------
      TextStrLen = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMTEXTA,long:iItem,lpbinary:LVITEM) ; call GETITEMTEXT and get it to fill our buffer with text
      BinaryEodSet(TextBuf,bufsize + 1)
      itemtext=BinaryPeekStr(TextBuf,0,bufsize) ;selected item
      If MatchCase == 0
        found = StrIndexNC(itemtext, text, 1, @FWDSCAN)
      Else
        found = StrIndex(itemtext, text, 1, @FWDSCAN)
      EndIf
      If found <> 0
        FoundIn = StrCat(iStart,delim,iSubitem)
        iStart = iEnd + 1
        iSubitem = iColEnd + 1
      EndIf
      BinaryEodSet(TextBuf,0)
      iSubitem = iSubitem + 1
   EndWhile
   iStart = iStart + 1
EndWhile
BinaryFree(LVITEM)
BinaryFree(TextBuf)
;dllfree(user32)
Return FoundIn
#EndFunction
;##########################################################################################################################################


;------------------------------------------------------------------------------------------------------------------------------------------;
;LVGetNextItem : Searches for a ListView item that has the specified properties and bears the specified relationship to a specified item.  ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                                        ;
;------------------------------------------------------------------------------------------------------------------------------------------;
;hListView      : ListView handle                                                                                                          ;
;iStart         : Index of the item to begin the search with, or -1 to find the first item that matches the specified flags.               ;
;                 (THE SPECIFIED ITEM ITSELF IS EXCLUDED FROM THE SEARCH)                                                                  ;
;flags          : Specifies the relationship to the item specified in iStart OR Specifies the State of the Item.                           ;
;                 This can be one or a combination of the following values:                                                                ;
;                 LVNI_ALL = 0         //Searches for a subsequent item by index, the default value.                                       ;
;                 LVNI_ABOVE = 256     //Searches for an item that is above the specified item.                                            ;
;                 LVNI_BELOW = 512     //Searches for an item that is below the specified item.                                            ;
;                 LVNI_TOLEFT = 1024   //Searches for an item to the left of the specified item.                                           ;
;                 LVNI_TORIGHT = 2048  //Searches for an item to the right of the specified item.                                          ;
;                 LVNI_CUT = 4         //The item has the LVIS_CUT state flag set.                                                         ;
;                 LVNI_DROPHILITED = 8 //The item has the LVIS_DROPHILITED state flag set                                                  ;
;                 LVNI_FOCUSED = 1     //The item has the LVIS_FOCUSED state flag set                                                      ;
;                 LVNI_SELECTED = 2    //The item has the LVIS_SELECTED state flag set.                                                    ;
;                                                                                                                                          ;
;    NOTE: IF AN ITEM DOES NOT HAVE ALL OF THE SPECIFIED STATE FLAGS SET, THE SEARCH CONTINUES WITH THE NEXT ITEM                          ;
;------------------------------------------------------------------------------------------------------------------------------------------;
;Returns        : Returns the index of the next item if successful, or -1 otherwise.                                                       ;
;------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetNextItem(hListView,iStart,flags)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETNEXTITEM = LVM_FIRST + 12
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETNEXTITEM,long:iStart,long:flags)
#EndFunction
;##########################################################################################################################################


;------------------------------------------------------------------------------------------------------------------------------;
;LVGetTopIndex : Retrieves the index of the topmost visible item in a ListView control when in LIST or REPORT view.            ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                            ;
;------------------------------------------------------------------------------------------------------------------------------;
;hListView      : ListView handle                                                                                              ;
;------------------------------------------------------------------------------------------------------------------------------;
;Returns        : Returns the index of the item if successful, or zero if the ListView control is in icon or small icon view.  ;
;------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetTopIndex(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETTOPINDEX = LVM_FIRST + 39
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETTOPINDEX,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------------------------------------------;
;LVScroll : Scrolls the content of a ListView control.                                                                                   ;
;v1.0 by IFICantBYTE (24 July 2003)                                                                                                      ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                            ;
;dx         : Value that specifies the amount of horizontal scrolling in pixels.                                                         ;
;      NOTE : If the ListView control is in LIST view, this value specifies the number of COLUMNS to scroll.                             ;
;dy         : Value that specifies the amount of vertical scrolling in pixels.                                                           ;
;      NOTE : When the ListView control is in report view, the control can only be scrolled vertically in whole line increments.         ;
;             Therefore, the dy parameter will be rounded to the nearest number of pixels that form a whole line increment.              ;
;             For example, if the height of a line is 16 pixels and 8 is passed for dy, the list will be scrolled by 16 pixels (1 line). ;
;             If 7 is passed for dy, the list will be scrolled 0 pixels (0 lines).                                                       ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns TRUE (1) if successful, or FALSE (0) otherwise                                                                     ;
;----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVScroll(hListView,dx,dy)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SCROLL = LVM_FIRST + 20
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SCROLL,long:dx,long:dy)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVEnsureVisible : Ensures that a ListView item is entirely visible, scrolling the ListView control if necessary                          ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;iItem      : Index of the Item you want to ensure is visible.                                                                            ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns TRUE (1) if successful, or FALSE (0) otherwise                                                                      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVEnsureVisible(hListView,iItem)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_ENSUREVISIBLE = LVM_FIRST + 19
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_ENSUREVISIBLE,long:iItem,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVArrange : Arranges items in ICON view.                                                                                                 ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;iItem      : Index of the Item you want to ensure is visible.                                                                            ;
;code       : The Alignment code to use.  This can be one of the following values:                                                        ;
;             LVA_ALIGNLEFT = 1    Aligns items along the left edge of the window.                                                        ;
;             LVA_ALIGNTOP = 2     Aligns items along the top edge of the window.                                                         ;
;             LVA_DEFAULT = 0      Aligns items according to the ListView control's CURRENT alignment styles (the default value).         ;
;             LVA_SNAPTOGRID = 5   Snaps all icons to the nearest grid position.                                                          ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns TRUE (1) if successful, or FALSE (0) otherwise                                                                      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVArrange(hListView,code)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_ARRANGE = LVM_FIRST + 22
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_ARRANGE,long:code,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVGetHotItem : Returns the index of the hot item.                                                                                        ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns the index of the item that is 'hot'.  (There can only be ONE hot item)                                              ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetHotItem(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETHOTITEM = LVM_FIRST + 61
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETHOTITEM,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSetHotItem : Sets the the hot item.  (There can only be ONE hot item)                                                                  ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;iIndex     : Zero based index of the item to be set as the hot item.                                                                     ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns the index of the item that was previously hot.                                                                      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetHotItem(hListView,iIndex)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_SETHOTITEM = LVM_FIRST + 60
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETHOTITEM,long:iIndex,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVHitTest : Determines which ListView Item, SubItem or Header Item, if any, is at a specified position*                                  ;
;            Also returns extended HitTest position information - see below for details                                                   ;
;            (*ListView's X,Y windows pixel client coordinates or points - not Winbatch 1000x1000 points - use UDF GetMouseWinCoordinates);
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                             ;
;x          : X coordinate to test at                                                                                                     ;
;y          : Y coordinate to test at                                                                                                     ;
;delim      : The delimiter you want to use between the returned X and Y values - eg: "," or @TAB or @CRLF or " " (space)                 ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns a delimited string of three values.  eg: 12,3,4    - each value represents the following:                           ;
;             First value  : The index of the matching parent item or -1 if there is no Item or SubItem at the coordinates given. If the  ;
;                            ListView is in REPORT view and the coordinates are over a header item then this value will be -2             ;
;             Second value : is the index of the matching subitem or header item. When hit-testing an item, this member will be zero.     ;
;             Third value  : is a value that contains bitwise OR'ed flag values about the results of the hit test....                     ;
;                            It can contain one or more of the following values:                                                          ;
;                     NOTE : LVHT_? values relate to The ListView window itself and HHT_? values relate to the Header of a ListView in    ;
;                            Report view, so these Third (flag) values can be the same but mean different things depending on the results ;
;                            of the hit-test coordinates and First value returned.                                                        ;
;                            LVHT_NOWHERE = 1         The point is inside the ListView control's client window, but not over a list item. ;
;                            LVHT_ONITEMICON = 2      The point is over a ListView item's icon.                                           ;
;                            LVHT_ONITEMLABEL = 4     The point is over a ListView item's text.                                           ;
;                            LVHT_ONITEMSTATEICON = 8 The point is over the state image of a ListView item.                               ;
;                            LVHT_ONITEM = 14         Combination of LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON = 14       ;
;                                                                                                                                         ;
;                            HHT_NOWHERE = 1          The point is inside the header's bounding rectangle but not over a header item.     ;
;                            HHT_ONDIVIDER = 4        The point is on the divider between two header items.                               ;
;                            HHT_ONDIVOPEN = 8        The point is on the divider of an item that has a width of zero. Dragging the       ;
;                                                     divider reveals the item instead of resizing the item to the left of the divider.   ;
;                            HHT_ONHEADER = 2         The point is inside the header control's bounding rectangle.                        ;
;                            HHT_ONFILTER = 16        Version 5.80+ of User32.dll The point is over the filter area.                      ;
;                            HHT_ONFILTERBUTTON = 32  Version 5.80+ of User32.dll The point is on the filter button.                      ;
;                                                                                                                                         ;
;                            ABOVE = 8           The point is above the control's client area.                                            ;
;                            BELOW = 16          The point is below the control's client area.                                            ;
;                            TORIGHT = 32        The point is to the right of the ListView control's client area.                         ;
;                            TOLEFT = 64         The point is to the left of the ListView control's client area.                          ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVItemHitTest(hListView,x,y,delim)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message that others are based on
LVM_SUBITEMHITTEST = LVM_FIRST + 57
LVM_GETHEADER = LVM_FIRST + 31
HDM_FIRST = 4608 ;Windows API Constant (in decimal) for the First Header Message that others are based on
HDM_HITTEST = HDM_FIRST + 6
   ;----- Make RECT structure ---- will contain the rectangle size of the client window -------------------
   RECTINFO=BinaryAlloc(16)    ; Create buffer for structure
   ;BinaryPoke4(RECTINFO,0,0)  ; Left x coordinate (pixel)
   ;BinaryPoke4(RECTINFO,4,0)  ; Top y coordinate (pixel)
   ;BinaryPoke4(RECTINFO,8,0)  ; Right x
   ;BinaryPoke4(RECTINFO,12,0) ; Bottom y
   ;NOTE : above BinaryPokes are commented out to save some processing time - contents will be overwritten with new values on dll call)
   ;-------------------------------------------------------------------------------------------------------
ret = DllCall(user32,long:"GetClientRect",long:hListView,lpbinary:RECTINFO)
Left = BinaryPeek4(RECTINFO,0)
Top = BinaryPeek4(RECTINFO,4)
Right = BinaryPeek4(RECTINFO,8)
Bottom = BinaryPeek4(RECTINFO,12)
BinaryFree(RECTINFO)
Flags = 0
If x < Left Then Flags = Flags | 64 ; If the mouse is left of the ListView Window's client area, set the Flag bits to 64
If x > Right Then Flags = Flags | 32 ; If the mouse is right
If y < Top Then Flags = Flags | 8 ; If mouse is above
If y > Bottom Then Flags = Flags | 16 ; If mouse is below
If Flags == 0 ;If mouse is somewhere inside the client area of the ListView window then do some HitTesting otherwise return -1 and the flags
   ;----- Make Generic HITTESTINFO structure ---- contains the position to hit test and receives information about the results of the hit test. -------------------
   HITTESTINFO=BinaryAlloc(20)        ; Create buffer for structure
   BinaryPoke4(HITTESTINFO,0,x) ; client x coordinate (pixel) to test for a hit (starting from 0 in top left corner of ListView Window)
   BinaryPoke4(HITTESTINFO,4,y) ; client y coordinate (pixel) to test for a hit (starting from 0 in top left corner of ListView Window)
                                  ; NOTE: the two 32bit 'LONG' values for x and y, when looked at together, form a 'point structure'
   ;BinaryPoke4(HITTESTINFO,8,0) ; will contain flags received
   ;BinaryPoke4(HITTESTINFO,12,0) ; will contain iItem received
   ;BinaryPoke4(HITTESTINFO,16,0) ; will contain iSubItem received - but only valid for Listview Items (in Report) not Header items
   ;(commented out some Pokes to save some processing time - will be overwritten with new value on dll call anyway)
   ;-----------------------------------------------------------------------------------------------------------------
   LVStyleNow = LVGetStyle(hListView) ; get the current style of the ListView Window and the ListView itself (WS_? and LVS_? API constants)
   If (LVStyleNow|3)-(LVStyleNow^3) <> 1 Then Goto LVHT  ; Work out what display mode the ListView is currently in (0=ICON, 1=REPORT, 2=SMALLICON, 3=LIST)
   hLVHeader = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETHEADER,long:0,long:0) ; get handle of header if in report view
   ret = DllCall(user32,long:"SendMessageA",long:hLVHeader,long:HDM_HITTEST,long:0,lpbinary:HITTESTINFO) ; header hittest
   Flags = BinaryPeek4(HITTESTINFO,8) ; Get HDFlags
   iItem = -2 ; We will use -2 to designate a header item hit (-1 means no hit and 0 is the first item)
   iCol = BinaryPeek4(HITTESTINFO,12) ; Get HDiItem
   If hLVHeader == 0 || ret == -1 Then Goto LVHT ; if the mouse is not over a header then check what it is over in the rest of the ListView window's client area
   Goto HTDONE
   :LVHT
   DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SUBITEMHITTEST,long:0,lpbinary:HITTESTINFO) ; listview hittest
   Flags = BinaryPeek4(HITTESTINFO,8) ; Get LVFlags
   iItem = BinaryPeek4(HITTESTINFO,12) ; Get LViItem
   iCol = BinaryPeek4(HITTESTINFO,16) ; Get LViSubItem
   :HTDONE
   BinaryFree(HITTESTINFO)
   ret = StrCat(iItem,delim,iCol,delim,Flags)
Else
   ret = StrCat(-1,delim,-1,delim,Flags)
EndIf
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVGetColumnCount : Gets the number of Columns in a ListView                                                                              ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                                              ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns : The number of Columns in a ListView or -1 on failure                                                                           ;
;   NOTE : The number returned is how many colums EXIST. NOT the index of the last column(SubItem), as column indexes are zero based and  ;
;          can be displayed in any order.                                                                                                 ;
;          eg: If there were 5 normal columns all visible and ordered left to right in a report view, the first column would contain the  ;
;          items, and be index 0, the last column would contain subitems at iSubItem index 4, so this LVGetColumnCount function would     ;
;          return a value of 5 ie: one more than the last column's index. (0,1,2,3,4 = 5 columns)                                         ;
;          Generally, only report style views have subitems and therefore columns, so other views would return a value of 0 (zero) BUT    ;
;          just to confuse things, a ListView can change views and can contain SubItems and columns and hidden headers etc.               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetColumnCount(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_GETHEADER = LVM_FIRST + 31
HDM_FIRST = 4608 ;Windows API Constant (in decimal) for the First Header Message address that others are based on
HDM_GETITEMCOUNT = HDM_FIRST ; Same value
LVHeader = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETHEADER,long:0,long:0)
ret = DllCall(user32,long:"SendMessageA",long:LVHeader,long:HDM_GETITEMCOUNT,long:0,long:0)
; Alternative more kludgy method....
;ret = -1
;LastColIndex = LVInsertColumn(hListView,9999,9999,0,"",-1) ; insert a temporary last column and return index
;  If LastColIndex >= 0
;  LVDeleteColumn(hListView,LastColIndex) ; delete the temporary column
;  ret = LastColIndex
;  EndIf
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVGetColumnWidth : Retrieves the width of a ListView column when in REPORT or LIST mode.                                                 ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                                              ;
;iCol      : Zero-based index of a valid column.                                                                                          ;
;     NOTE : When ListView is in LIST mode (LVS_LIST style applied), this parameter is ignored.                                           ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : Returns the column width if successful, or zero otherwise.                                                                   ;
;     NOTE : If this command is used on a ListView control with the LVS_REPORT style and the specified column doesn't exist, the return   ;
;            value is undefined.                                                                                                          ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetColumnWidth(hListView,iCol)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_GETCOLUMNWIDTH = LVM_FIRST + 29
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETCOLUMNWIDTH,long:iCol,long:0)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSetColumnWidth : Changes the width of a ListView column in REPORT mode or the width of all columns in LIST mode.                       ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                                              ;
;iCol      : Zero-based index of a valid column. When ListView is in LIST mode, this parameter must be set to zero.                       ;
;cx        : New width of the column, in pixels.                                                                                          ;
;            For REPORT mode, the following special values are supported:                                                                 ;
;                LVSCW_AUTOSIZE = -1           Automatically sizes the column.                                                            ;
;                LVSCW_AUTOSIZE_USEHEADER = -2 Automatically sizes the column to fit the header text.                                     ;
;                                              If you use this value with the last column, its width is set to fill the remaining width   ;
;                                              of the ListView control.                                                                   ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns       : TRUE(1) if successful, or FALSE(0) otherwise.                                                                            ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetColumnWidth(hListView,iCol,cx)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_SETCOLUMNWIDTH = LVM_FIRST + 30
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETCOLUMNWIDTH,long:iCol,long:cx)
#EndFunction
;##########################################################################################################################################

;Get Returns: MaskValue,Format,Width,Text,SubItem,iImage,iOrder
;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSetColumn : Sets the attributes of a list-view column.                                                                                 ;
;v2.9 by IFICantBYTE (2012)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                                              ;
;iCol      : Zero-based index of a valid column.                                                                                          ;
;text not finished here
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : TRUE(1) if successful, or FALSE(0) otherwise.                                                                                ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetColumn(hListView,iCol,mask,frmt,cx,text,iSubItem,iImage,iOrder)
;old#definefunction LVSetColumn(hListView,iCol,iSubItem,cx,text,iImage)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_SETCOLUMNA = LVM_FIRST + 26
;#definefunction LVInsertColumn(hListView,iCol,iSubItem,cx,text,iImage)
;iOrder = iCol ;Zero-based column offset. Column offset is in left-to-right order.

TextBuf=BinaryAlloc(StrLen(text)+1)
   BinaryPokeStr(TextBuf,0,text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;----- Make Column structure -------------------------------------------------------
   LVCOLUMN=BinaryAlloc(32)                 ; Create buffer for structure
   BinaryPoke4(LVCOLUMN,0,mask);olddefaults: 1|2|4|8|16|32    ; mask (see LVCF_?????? Windows API constants)
   BinaryPoke4(LVCOLUMN,4,frmt);olddefaults: 0|2048|4096|32768; frmt (see LVCFMT_???? Windows API constants)
   BinaryPoke4(LVCOLUMN,8,cx)               ; cx
   BinaryPoke4(LVCOLUMN,12,TextAd)          ; pszText // address of pointer to text string for column header name
   BinaryPoke4(LVCOLUMN,16,255)             ; cchTextMax
   BinaryPoke4(LVCOLUMN,20,iSubItem)        ; iSubItem
   BinaryPoke4(LVCOLUMN,24,iImage)          ; iImage  // Zero-based index of an image within the image list to put in the column
   BinaryPoke4(LVCOLUMN,28,iOrder)          ; iOrder  // Zero-based column offset. Column offset is in left-to-right order.
   ;-----------------------------------------------------------------------------------

ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETCOLUMNA,long:iCol,lpbinary:LVCOLUMN)
BinaryFree(LVCOLUMN)
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVGetColumn : Gets Column attributes.                                                                                                    ;
;v1.4 by IFICantBYTE                                                                                                                      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : ListView handle.                                                                                                           ;
;iCol        : Index of the Column you wish to return the attributes of.                                                                  ;
;delim       : Delimiter to put between each of the attributes returned.                                                                  ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : A list of the 7 column attributes listed below seperated by a user-defined delimiter.                                      ;
;              eg:   MaskValue,Format,Width,Text,SubItem,iImage,iOrder                                                                    ;
;              - this way a valid Winbatch List with @TAB delimiters or CSV can be passed back and itemized by other commands.            ;
;                A SPACE delimited string could also be parsed by the ParseData command - assuming you allow for any text in the column   ;
;                name that may also contain spaces.                                                                                       ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetColumn(hListView,iCol,delim)
user32=StrCat(DirWindows(1),"user32.dll")

LVM_FIRST = 4096
LVM_GETCOLUMNA = LVM_FIRST + 25

TextBuf=BinaryAlloc(256)
TextAd=IntControl(42,TextBuf,0,0,0)

   ;----- Make Column structure -------------------------------------------------------
   LVCOLUMN=BinaryAlloc(32)                  ; Create buffer for structure
   BinaryPoke4(LVCOLUMN,0,1|2|4|8|16|32)     ; mask (see LVCF_?????? Windows API constants)
   ;BinaryPoke4(LVCOLUMN,4,0|2048|4096|32768); frmt (see LVCFMT_???? Windows API constants)
   ;BinaryPoke4(LVCOLUMN,8,cx)               ; cx
   BinaryPoke4(LVCOLUMN,12,TextAd)           ; pszText // address of pointer to text string for column header name
   BinaryPoke4(LVCOLUMN,16,255)              ; cchTextMax
   ;BinaryPoke4(LVCOLUMN,20,iSubItem)        ; iSubItem
   ;BinaryPoke4(LVCOLUMN,24,iImage)          ; iImage  // Zero-based index of an image within the image list to put in the column
   ;BinaryPoke4(LVCOLUMN,28,iOrder)          ; iOrder  // Zero-based column offset. Column offset is in left-to-right order. - we are setting this to be the same as iCol - but it doesn't have to be - can get confusing though
   ;-----------------------------------------------------------------------------------
   DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETCOLUMNA,long:iCol,lpbinary:LVCOLUMN)

   ;-----Collect LVITEM data----------------------------------------------------
   RetMask = BinaryPeek4(LVCOLUMN,0)        ; mask
   RetFrmt = BinaryPeek4(LVCOLUMN,4)        ; frmt
   RetCx = BinaryPeek4(LVCOLUMN,8)          ; cx
   BinaryEodSet(TextBuf,BinaryPeek4(LVCOLUMN,16))
   RetText = BinaryPeekStr(TextBuf,0,BinaryPeek4(LVCOLUMN,16)) ; The text
   RetiSubItem = BinaryPeek4(LVCOLUMN,20)   ; iSubItem
   RetiImage = BinaryPeek4(LVCOLUMN,24)     ; iImage
   RetiOrder = BinaryPeek4(LVCOLUMN,28)     ; iOrder
   ;-------------------------------------------------------------------------------

BinaryFree(LVCOLUMN)
BinaryFree(TextBuf)
Return (StrCat(RetMask,delim,RetFrmt,delim,RetCx,delim,RetText,delim,RetiSubItem,delim,RetiImage,delim,RetiOrder))
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSetIconSpacing : Sets the spacing between icons in ListView controls that have the LVS_ICON style and returns the previous values in a ;
;                   delimited string.                                                                                                     ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView     : ListView handle                                                                                                          ;
;iCol          : Zero-based index of a valid column. When ListView is in LIST mode, this parameter must be set to zero.                   ;
;cx            : Distance, in pixels, to set between icons on the x-axis.                                                                 ;
;cy            : Distance, in pixels, to set between icons on the y-axis.                                                                 ;
;         NOTE : Values for cx and cy are relative to the upper-left corner of an icon bitmap. Therefore, to set spacing between icons    ;
;                that do not overlap, the cx or cy values must include the size of the icon, plus the amount of empty space desired       ;
;                between icons. Values that do not include the width of the icon will result in overlaps.                                 ;
;                When defining the icon spacing, cx and cy must be set to 4 or larger. Smaller values will not yield the desired layout.  ;
;                To reset cx and cy to the default spacing, set the lParam value to -1                                                    ;
;delim         : Delimiter to insert between the returned values.                                                                         ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns       : Returns a delimited string containing the previous cx and cy values.                                                     ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSetIconSpacing(hListView,cx,cy,delim)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_SETICONSPACING = LVM_FIRST + 53
;----- Convert two 16bit integers (WORDS) to a 32bit integer (LONG or DWORD) ------
MAKELONG=BinaryAlloc(4)       ; Create buffer
BinaryPoke2(MAKELONG,0,cx)    ; first value
BinaryPoke2(MAKELONG,2,cy)    ; second value
CxCy = BinaryPeek4(MAKELONG,0)
;Let's re-use this buffer for the returned previous values
BinaryPoke4(MAKELONG,0,DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETICONSPACING,long:0,long:CxCy))
ret = StrCat(BinaryPeek2(MAKELONG,0),delim,BinaryPeek2(MAKELONG,2))
BinaryFree(MAKELONG)
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVSortItems : Sorts or inverts the Items in a ListView control using a custom compare routine.                                           ;
;              Sorts can be made against any Item or Subitem text or numeric value as well as sorts made by comparing the values held in  ;
;              the item's other attributes such as lparam value, icon image, state value or indent.                                       ;
;v1.3 by ....IFICantBYTE                                                                                                                  ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView : ListView handle                                                                                                              ;
;column    : Column (Item or SubItem) to order the list by (SubItems, if any, are only visible in Report view but can still be used)      ;
;direction : 0 = Ascending (in numeric or ASCII value from top to bottom), 1 = Decending, anything else = Flip(invert) list without sort  ;
;dataflag  : Datatype or method to sort by.                                                                                               ;
;            0=itemtext using lexical ASCII sort, 1=itemtext using numeric sort, 2,3,4,5=spare, 6=lParam, 7=iImage, 8=state, 9=iIndent    ;
;  EXAMPLES: LVSortItems(MyLVhandle,3,0,0) would sort the list by subitem 3's text data, treating it as ASCII string data from A to Z     ;
;            LVSortItems(MyLVhandle,2,1,1) would sort the list by subitem 2's text data, treating it as numeric data with largest at top  ;
;            LVSortItems(MyLVhandle,0,0,6) would use the item's lParam (32bit user defined number) to sort on Smallest to Largest value   ;
;            LVSortItems(MyLVhandle,5,0,7) would sort the list by subitem 5's icons, using the index value of the icon to group them      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns TRUE (1) if successful, or FALSE (0) otherwise                                                                      ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVSortItems(hListView,column,direction,dataflag)
hkernel32 = StrCat(DirWindows(1),"kernel32.dll")
user32=StrCat(DirWindows(1),"user32.dll")
LVSortCmp = StrCat(DirWindows(1),"LVSortCmp.dll") ;you can change the path if you like
If FileExist(LVSortCmp)
Loadmydll = DllCall(hkernel32,long:"LoadLibraryA",lpstr:LVSortCmp)
Else
HEX = ArrDimension(26)
HEX[0]="4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000B00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400"
HEX[1]="0000000000005DF3DCFD1992B2AE1992B2AE1992B2AEE5B2A0AE1892B2AE978DA1AE1092B2AE526963681992B2AE0000000000000000504500004C01040024BD1A410000000000000000E0000E210B01050C00020000000600000000000026100000001000000020000000000010001000000002000004000000"
HEX[2]="00000000040000000000000000500000000400000000000002000000000010000010000000001000001000000000000010000000A02000004E000000102000003C000000000000000000000000000000000000000000000000000000004000001000000000000000000000000000000000000000000000000000"
HEX[3]="000000000000000000000000000000000000000000000000000000200000100000000000000000000000000000000000000000000000000000002E74657874000000F8010000001000000002000000040000000000000000000000000000200000602E72646174610000EE000000002000000002000000060000"
HEX[4]="000000000000000000000000400000402E6461746100000014000000003000000002000000080000000000000000000000000000400000C02E72656C6F630000260000000040000000020000000A0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000"
HEX[5]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[6]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[7]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[8]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004C56736F7274436F6D70617265204279202E2E2E2E49464943616E7442595445203230303400558BEC837D0C017510FF75088F0510300010B801000000EB16837D0C007502EB0E837D0C"
HEX[9]="027502EB06837D0C037500C9C20C00558BEC5633C08B750833C933D28A0646EB0B2C308D0C898D0C488A06460AC075F18D040A5EC9C20400558BEC81C4B0FDFFFF608B7D108B378B5F048B45088945DC895DE0C745D81F000000C745E8FFFFFFFF8D85B0FEFFFF8945ECC745F0FF0000008D45D8506A00680510"
HEX[10]="000056E8200100008B450C8945B4895DB8C745B01F000000C745C0FFFFFFFF8D85B0FDFFFF8945C4C745C8FF0000008D45B0506A00680510000056E8E8000000837F08017605E9C8000000837F0C00765A837F0C0975088B45FC8BF08B45D4837F0C0875088B45E48BF08B45BC837F0C0775088B45F48BF08B45"
HEX[11]="CC837F0C0675088B45F88BF08B45D0837F0C01756A8D85B0FEFFFF50E8FAFEFFFF8BF08D85B0FDFFFF50E8ECFEFFFFEB4E837F080075226AFF8D85B0FDFFFF506AFF8D85B0FEFFFF506A006A00E86200000083E802EB34EB26837F080175206AFF8D85B0FEFFFF506AFF8D85B0FDFFFF506A006A00E83A000000"
HEX[12]="83E802EB0C837F080175042BC6EB022BF07416770A61B8FFFFFFFFC9C20C0061B801000000C9C20C0061B800000000C9C20C00CCFF2508200010FF2500200010000000000000000078200000000000005C200000000000005420000000000000000000006C200000082000004C20000000000000000000008A20"
HEX[13]="000000200000000000000000000000000000000000000000000078200000000000005C20000000000000E20153656E644D6573736167654100007573657233322E646C6C00001E00436F6D70617265537472696E674100006B65726E656C33322E646C6C000000000000000000000000000024BD1A4100000000"
HEX[14]="D2200000010000000100000001000000C8200000CC200000D020000082100000E420000000004C56536F7274436F6D706172652E646C6C004C56536F7274436D70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[15]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[16]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[17]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[18]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[19]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[20]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010"
HEX[21]="0000100000003430EE31F4310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[22]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[23]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[24]="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
HEX[25]="00000000000000000000000000000000000000000000"

HEXBUFEOD = 0
HEXBYTESSTORED = 0
HEXBINBUF = BinaryAlloc(3100)
For HEXC = 0 To 25
HEXBYTESSTORED = BinaryPokeHex(HEXBINBUF,HEXBUFEOD, HEX[%HEXC%])
HEXBUFEOD = HEXBUFEOD + HEXBYTESSTORED
Next HEXC
BinaryEodSet(HEXBINBUF,HEXBUFEOD)
BinaryWrite(HEXBINBUF,LVSortCmp);save the LV sort compare dll
BinaryFree(HEXBINBUF)
DropWild("HEX*")
LoadMyDll = DllCall(hkernel32,long:"LoadLibraryA",lpstr:LVSortCmp)
EndIf

LVM_FIRST = 4096
LVM_SORTITEMSEX = LVM_FIRST + 81
   ;----- Make SORT structure ------------------------------------
   PASSME=BinaryAlloc(16) ; Create buffer for our sort structure
   BinaryPoke4(PASSME,0,hListView) ; LVhandle
   BinaryPoke4(PASSME,4,column) ; column
   BinaryPoke4(PASSME,8,direction) ; direction : 0=decending, 1=ascending, >1=Invert list
   BinaryPoke4(PASSME,12,dataflag) ; dataflag : 0=itemtext lex ASCII, 1=itemtext num, 2,3,4,5=spare, 6=lParam, 7=iImage, 8=state, 9=iIndent
   ;------------------------------------------------------------------------------------------------------
FunctionName = "LVSortCmp"
Ret = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SORTITEMSEX,lpbinary:PASSME,long:DllCall(hkernel32,long:"GetProcAddress",long:LoadMyDll,lpstr:FunctionName))
BinaryFree(PASSME)
Return Ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVEditLabel : Begins in-place editing of the specified ListView item's text.                                                             ;
;              NOTE: The message implicitly SELECTS and FOCUSES the specified item.                                                       ;
;v2.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : Handle to the ListView Control                                                                                             ;
;iItem       : Index of the ListView item.                                                                                                ;
;       NOTE : To cancel editing, set iItem to -1                                                                                         ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : Returns the handle to the edit control that is used to edit the item text if successful, or NULL otherwise.                ;
;       NOTE : When the user completes or cancels editing, the edit control is destroyed and the handle is no longer valid.               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVEditLabel(hListView,iItem)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_EDITLABELA = LVM_FIRST + 23
DllCall(user32,long:"SetFocus",long:hListView) ; The ListView must have the focus before you send the LVM_EDITLABELA message.
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_EDITLABELA,long:iItem,long:0)
#EndFunction
;##########################################################################################################################################
;-----------------------------------------------------------------------------------------------------------------------------------------;
;LVEditLabel : Begins in-place editing of the specified ListView item's text.                                                             ;
;              NOTE: The message implicitly SELECTS and FOCUSES the specified item.                                                       ;
;v2.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hListView   : Handle to the ListView Control                                                                                             ;
;iItem       : Index of the ListView item.                                                                                                ;
;       NOTE : To cancel editing, set iItem to -1                                                                                         ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns     : Returns the handle to the edit control that is used to edit the item text if successful, or NULL otherwise.                ;
;       NOTE : When the user completes or cancels editing, the edit control is destroyed and the handle is no longer valid.               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetCountPerPage(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096 ;Windows API Constant (in decimal) for the First ListView Message address that others are based on
LVM_GETCOUNTPERPAGE = LVM_FIRST + 40
;dllcall(user32,long:"SetFocus",long:hListView) ; The ListView must have the focus before you send the LVM_EDITLABELA message.
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETCOUNTPERPAGE,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------------------------------------------;
;LVGetEditControl : Retrieves the handle to the edit control being used to edit a ListView item's text.                                  ;
;v2.1 by IFICantBYTE (2004)                                                                                                              ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle                                                                                                            ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns the handle to the edit control if successful, or NULL otherwise.                                                   ;
;----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVGetEditControl(hListView)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETEDITCONTROL = LVM_FIRST + 24
Return DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETEDITCONTROL,long:0,long:0)
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------------------------------------------;
;LVSaveItems : Saves the ListView item data to a comma delimited file.                                                                   ;
;              This file can be loaded later using the opposite function "LVLoadItems" to recreate the same ListView                     ;
;v2.6 by ....IFICantBYTE (2005)                                                                                                          ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle.                                                                                                           ;
;LVFileName : Filename (and path) to save the ListView data in.                                                                          ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Returns the size in bytes of the file saved.                                                                               ;
;----------------------------------------------------------------------------------------------------------------------------------------;

#DefineFunction LVSaveItems(hListView,LVFileName)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_GETITEMA = LVM_FIRST + 5
LVM_GETCOLUMNA = LVM_FIRST + 25
WS_CHILD = 1073741824
WS_VISIBLE = 268435456
WS_CAPTION = 12582912
WS_EX_CLIENTEDGE = 512
WM_USER = 1024
PBM_SETRANGE32 = WM_USER + 6
PBM_SETSTEP = WM_USER + 4
PBM_STEPIT = WM_USER + 5
PBM_SETBARCOLOR = WM_USER + 9

TextBuf=BinaryAlloc(256)
TextAd=IntControl(42,TextBuf,0,0,0)

LVItemCount = LVGetItemCount(hListView)
LVColCount = LVGetColumnCount(hListView)

LVSave = ArrDimension(LVItemCount+1,LVColCount*10) ; First Dim is for every item plus one for header, Second Dim has 10 values for each Item/SubItem.
                                                   ; 10 was easier to understand and leaves a few spare for future use - perhaps to save colour, icon file or view mode information etc.
                                                   ;- I thought I'd keep it fairly simple for now. ....IFICantBYTE :-)
ArrInitialize(LVSave,"")

RECTINFO = BinaryAlloc(16)    ; Create buffer for RECT structure
ret = DllCall(user32,long:"GetClientRect",long:hListView,lpbinary:RECTINFO)
Left = BinaryPeek4(RECTINFO,0)
Top = BinaryPeek4(RECTINFO,4)
Right = BinaryPeek4(RECTINFO,8)
Bottom = BinaryPeek4(RECTINFO,12)
BinaryFree(RECTINFO)
LVxSize = Right - Left
LVySize = Bottom - Top
PBWidth = Abs((LVxSize*.01)*80) ; 80 percent of LV width
PBLeft = Abs(0 + ((LVxSize - PBWidth)*.5)) ; Use this as Left
If LVxSize > 180 && LVySize > 80
WS_STYLE = WS_CAPTION|WS_CHILD|WS_VISIBLE ; There is enough room to use a Caption to display a saving message.
PBHeight = Abs(((LVySize*.01)*15)+25) ; 15 percent of LV Height + a bit more for Caption
PBTop = Abs((LVySize * .5) - (PBHeight * .5)) ; Use this as Top ~ should be in the centre of the ListView Window with these sizes.
Else
WS_STYLE = WS_CHILD|WS_VISIBLE
PBHeight = Abs((LVySize*.01)*15) ; 15 percent of LV Height
PBTop = Abs((LVySize * .5) - (PBHeight * .5)) ; Use this as Top ~ should be in the centre of the ListView Window with these sizes.
EndIf

SaveMsg = StrCat("Saving:  ",LVFileName)
;create the progress bar inside our ListView window - if the window is big enough, the ProgBar will have a caption too, with "Saving: FileName" in it. - Note: Logical OR a 1 to the style to make a smooth looking bar.
hProgBar = DllCall(user32,long:"CreateWindowExA",long:WS_EX_CLIENTEDGE,lpstr:"msctls_progress32",lpstr:SaveMsg,long:WS_STYLE,long:PBLeft,long:PBTop,long:PBWidth,long:PBHeight,long:hListView,long:8999,long:DllHinst(""),long:0)
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETBARCOLOR,long:0,long:38400) ; make it green
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETRANGE32,long:0,long:LVItemCount+LVColCount) ; set the range to match our array data numbers
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETSTEP,long:1,long:0) ; set the increment value

ItemX = 0
LVITEM=BinaryAlloc(40)          ; Create buffer for LVITEM structure

While ItemX < LVItemCount
   DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_STEPIT,long:0,long:0) ; increment the progress bar
   ColX = 0
   ;-----Make LVITEM structure----------------------------------------------------
   BinaryPoke4(LVITEM,0,31)        ; mask  = (1|2|4|8|16) See API LVIF_ values
   BinaryPoke4(LVITEM,4,ItemX)     ; iItem
   BinaryPoke4(LVITEM,8,ColX)      ; iSubitem
   BinaryPoke4(LVITEM,12,65295)    ; state  = (1|2|4|8|3840|61440) See API LVIS_ values
   BinaryPoke4(LVITEM,16,-1)       ; stateMask  (-1 = All states)
   BinaryPoke4(LVITEM,20,TextAd)   ; pszText
   BinaryPoke4(LVITEM,24,255)      ; cchTextMax
   ;BinaryPoke4(LVITEM,28,0)       ; iImage
   ;BinaryPoke4(LVITEM,32,0)       ; LParam
   ;BinaryPoke4(LVITEM,36,0)       ; iIndent
   ;-------------------------------------------------------------------------------
   GetItAll = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMA,long:0,lpbinary:LVITEM)
   Dim2X = ColX*10
   ;-----Collect LVITEM data----------------------------------------------------
   LVSave[ItemX,Dim2X] = BinaryPeek4(LVITEM,0)        ; mask  = (1|2|4|8|16) See API LVIF_ values
   LVSave[ItemX,Dim2X+1] = BinaryPeek4(LVITEM,12)     ; state  = (1|2|4|8|3840|61440) See API LVIS_ values
   BinaryEodSet(TextBuf,BinaryPeek4(LVITEM,24) + 1)
   LVSave[ItemX,Dim2X+2] = BinaryPeekStr(TextBuf,0,BinaryPeek4(LVITEM,24)) ; The text
   LVSave[ItemX,Dim2X+3] = BinaryPeek4(LVITEM,28)     ; iImage
   LVSave[ItemX,Dim2X+4] = BinaryPeek4(LVITEM,32)     ; LParam
   LVSave[ItemX,Dim2X+5] = BinaryPeek4(LVITEM,36)     ; iIndent
   ;Dim2X+6 to Dim2X+9 are spare for future use
   ;-------------------------------------------------------------------------------
   ColX = 1

   While ColX < LVColCount ; We will treat SubItems differently, collecting only a portion of the information we did for Items
       ;-----Make LVITEM structure----------------------------------------------------
       BinaryPoke4(LVITEM,0,3)        ; mask  = (1|2) Just Text and Image ~ See API LVIF_ values
       BinaryPoke4(LVITEM,4,ItemX)     ; iItem
       BinaryPoke4(LVITEM,8,ColX)      ; iSubitem
       ;BinaryPoke4(LVITEM,12,65295)    ; state  = (1|2|4|8|3840|61440) See API LVIS_ values
       ;BinaryPoke4(LVITEM,16,-1)       ; stateMask  (-1 = All states)
       BinaryPoke4(LVITEM,20,TextAd)   ; pszText
       BinaryPoke4(LVITEM,24,255)      ; cchTextMax
       ;BinaryPoke4(LVITEM,28,0)       ; iImage
       ;BinaryPoke4(LVITEM,32,0)       ; LParam
       ;BinaryPoke4(LVITEM,36,0)       ; iIndent
       ;-------------------------------------------------------------------------------
       GetItAll = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETITEMA,long:0,lpbinary:LVITEM)
       Dim2X = ColX*10
       ;-----Collect LVITEM data----------------------------------------------------
       LVSave[ItemX,Dim2X] = BinaryPeek4(LVITEM,0)        ; mask  = (1|2|4|8|16) See API LVIF_ values
       ;LVSave[ItemX,Dim2X+1] = BinaryPeek4(LVITEM,12)     ; state  = (1|2|4|8|3840|61440) See API LVIS_ values
       BinaryEodSet(TextBuf,BinaryPeek4(LVITEM,24) + 1)
       LVSave[ItemX,Dim2X+2] = BinaryPeekStr(TextBuf,0,BinaryPeek4(LVITEM,24)) ; The text
       LVSave[ItemX,Dim2X+3] = BinaryPeek4(LVITEM,28)     ; iImage
       ;LVSave[ItemX,Dim2X+4] = BinaryPeek4(LVITEM,32)     ; LParam
       ;LVSave[ItemX,Dim2X+5] = BinaryPeek4(LVITEM,36)     ; iIndent
       ;Dim2X+1 and Dim2X+4 to 9 are spare - they could be used to store other info in a later version.
       ;NOTE: saving and setting state info on SubItems can give you some unusual results later, but could be useful.
       ;      lParam and iIndent are not supported by SubItems.
       ;-------------------------------------------------------------------------------
       ColX = ColX + 1
   EndWhile
   ItemX = ItemX + 1
EndWhile
BinaryFree(LVITEM)
ColX = 0
While ColX < LVColCount
   DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_STEPIT,long:0,long:0) ; increment the progress bar
   ;----- Make Column structure -------------------------------------------------------
   LVCOLUMN=BinaryAlloc(32)                 ; Create buffer for structure
   BinaryPoke4(LVCOLUMN,0,1|2|4|8|16|32)    ; mask (see LVCF_?????? Windows API constants)
   ;BinaryPoke4(LVCOLUMN,4,0|2048|4096|32768); frmt (see LVCFMT_???? Windows API constants)
   ;BinaryPoke4(LVCOLUMN,8,cx)               ; cx
   BinaryPoke4(LVCOLUMN,12,TextAd)          ; pszText // address of pointer to text string for column header name
   BinaryPoke4(LVCOLUMN,16,255)             ; cchTextMax
   ;BinaryPoke4(LVCOLUMN,20,iSubItem)        ; iSubItem
   ;BinaryPoke4(LVCOLUMN,24,iImage)          ; iImage  // Zero-based index of an image within the image list to put in the column
   ;BinaryPoke4(LVCOLUMN,28,iOrder)          ; iOrder  // Zero-based column offset. Column offset is in left-to-right order. - we are setting this to be the same as iCol - but it doesn't have to be - can get confusing though
   ;-----------------------------------------------------------------------------------
   GetHeader = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_GETCOLUMNA,long:ColX,lpbinary:LVCOLUMN)
   Dim2X = ColX*10
   ;-----Collect LVITEM data----------------------------------------------------
   LVSave[ItemX,Dim2X] = BinaryPeek4(LVCOLUMN,0)       ; mask
   LVSave[ItemX,Dim2X+1] = BinaryPeek4(LVCOLUMN,4)     ; frmt
   LVSave[ItemX,Dim2X+2] = BinaryPeek4(LVCOLUMN,8)     ; cx
   BinaryEodSet(TextBuf,BinaryPeek4(LVCOLUMN,16))
   LVSave[ItemX,Dim2X+3] = BinaryPeekStr(TextBuf,0,BinaryPeek4(LVCOLUMN,16)) ; The text
   ;LVSave[ItemX,Dim2X+4] = BinaryPeek4(LVCOLUMN,16)     ; cchTextMax
   LVSave[ItemX,Dim2X+4] = BinaryPeek4(LVCOLUMN,20)     ; iSubItem
   LVSave[ItemX,Dim2X+5] = BinaryPeek4(LVCOLUMN,24)     ; iImage
   LVSave[ItemX,Dim2X+6] = BinaryPeek4(LVCOLUMN,28)     ; iOrder
   ;Dim2X+7 to Dim2X+9 are spare for future use (very last is used for LVSaveItems UDF file version stamp)
   ;-------------------------------------------------------------------------------
   ColX = ColX + 1
EndWhile
BinaryFree(LVCOLUMN)
BinaryFree(TextBuf)
LVSave[LVItemCount,(LVColCount*10)-1] = "LVSaveItemsV1.0" ; save file version stamp incase we ever make a newer extended UDF and need to know the difference for import conversion etc.
DllCall(user32,long:"DestroyWindow",long:hProgBar) ; destroy the progress bar
ret = ArrayFilePutCSV(LVFileName,LVSave,",",@TRUE,0)
Drop(LVSave)
Return ret
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------------------------------------------------------------------;
;LVLoadItems : Loads the ListView item data from a comma delimited file.                                                                 ;
;              This file can be one saved by the opposite function "LVSaveItems"                                                         ;
;v2.6 by ....IFICantBYTE (2005)                                                                                                          ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;hListView  : ListView handle.                                                                                                           ;
;LVFileName : Filename (and path) to load the ListView data from.                                                                        ;
;----------------------------------------------------------------------------------------------------------------------------------------;
;Returns    : Number of items loaded                                                                                                     ;
;----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LVLoadItems(hListView,LVFileName)
user32=StrCat(DirWindows(1),"user32.dll")
LVM_FIRST = 4096
LVM_INSERTCOLUMNA = LVM_FIRST + 27
LVM_INSERTITEMA = LVM_FIRST + 7
LVM_SETITEMA = LVM_FIRST + 6
WS_CHILD = 1073741824
WS_VISIBLE = 268435456
WS_CAPTION = 12582912
WS_EX_CLIENTEDGE = 512
WM_USER = 1024
PBM_SETRANGE32 = WM_USER + 6
PBM_SETSTEP = WM_USER + 4
PBM_STEPIT = WM_USER + 5
PBM_SETBARCOLOR = WM_USER + 9

TextBuf=BinaryAlloc(256)
TextAd=IntControl(42,TextBuf,0,0,0)

LVLoad = ArrayFileGetCSV(LVFileName, 0, ",", 0, 0) ; Load the ListView data file
LVItemCount = ArrInfo(LVLoad,1) - 1
LVColCount = ArrInfo(LVLoad,2)/10 ; There are 10 elements in each column of our file.
                                  ; 10 was easier to understand and leaves a few spare for future use - perhaps to save colour, icon file or view mode information etc. - I thought I'd keep it fairly simple for now. ....IFICantBYTE :-)

;LVDeleteItem(hListView,-1)
;ExistingCol = LVGetColumnCount(hListView)
;If ExistingCol > 1
;For DelCol = ExistingCol to 1 by -1
;LVDeleteColumn(hListView,DelCol)
;Next DelCol
;EndIf


RECTINFO = BinaryAlloc(16)    ; Create buffer for RECT structure
ret = DllCall(user32,long:"GetClientRect",long:hListView,lpbinary:RECTINFO)
Left = BinaryPeek4(RECTINFO,0)
Top = BinaryPeek4(RECTINFO,4)
Right = BinaryPeek4(RECTINFO,8)
Bottom = BinaryPeek4(RECTINFO,12)
BinaryFree(RECTINFO)
LVxSize = Right - Left
LVySize = Bottom - Top
PBWidth = Abs((LVxSize*.01)*80) ; 80 percent of LV width
PBLeft = Abs(0 + ((LVxSize - PBWidth)*.5)) ; Use this as Left
If LVxSize > 180 && LVySize > 80
WS_STYLE = WS_CAPTION|WS_CHILD|WS_VISIBLE ; There is enough room to use a Caption to display a loading message.
PBHeight = Abs(((LVySize*.01)*15)+25) ; 15 percent of LV Height + a bit more for Caption
PBTop = Abs((LVySize * .5) - (PBHeight * .5)) ; Use this as Top ~ should be in the centre of the ListView Window with these sizes.
Else
WS_STYLE = WS_CHILD|WS_VISIBLE
PBHeight = Abs((LVySize*.01)*15) ; 15 percent of LV Height
PBTop = Abs((LVySize * .5) - (PBHeight * .5)) ; Use this as Top ~ should be in the centre of the ListView Window with these sizes.
EndIf

LoadMsg = StrCat("Loading:  ",LVFileName)
hProgBar = DllCall(user32,long:"CreateWindowExA",long:WS_EX_CLIENTEDGE,lpstr:"msctls_progress32",lpstr:LoadMsg,long:WS_STYLE,long:PBLeft,long:PBTop,long:PBWidth,long:PBHeight,long:hListView,long:8999,long:DllHinst(""),long:0)
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETBARCOLOR,long:0,long:200)
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETRANGE32,long:0,long:LVItemCount+LVColCount)
DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_SETSTEP,long:1,long:0)

LVCOLUMN=BinaryAlloc(32) ; Create buffer for COLUMN structure

ColX = 0
While ColX < LVColCount
   DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_STEPIT,long:0,long:0) ; increment the progress bar
   Dim2X = ColX*10
   ;----- Make Column structure -------------------------------------------------------
   BinaryPoke4(LVCOLUMN,0,LVLoad[LVItemCount,Dim2X])    ; mask (see LVCF_?????? Windows API constants)
   BinaryPoke4(LVCOLUMN,4,LVLoad[LVItemCount,Dim2X+1])  ; frmt (see LVCFMT_???? Windows API constants)
   BinaryPoke4(LVCOLUMN,8,LVLoad[LVItemCount,Dim2X+2])  ; cx
   BinaryPokeStr(TextBuf,0,LVLoad[LVItemCount,Dim2X+3]) ; Poke the text string into the buffer
   BinaryPoke(TextBuf,StrLen(LVLoad[LVItemCount,Dim2X+3]),0) ; Terminate buffer with a NULL
   BinaryPoke4(LVCOLUMN,12,TextAd)                      ; pszText // address of pointer to text string for column header name
   BinaryPoke4(LVCOLUMN,16,StrLen(LVLoad[LVItemCount,Dim2X+3])) ; cchTextMax ~ not needed when inserting - looks for NULL in buffer
   BinaryPoke4(LVCOLUMN,20,LVLoad[LVItemCount,Dim2X+4]) ; iSubItem
   BinaryPoke4(LVCOLUMN,24,LVLoad[LVItemCount,Dim2X+5]) ; iImage
   BinaryPoke4(LVCOLUMN,28,LVLoad[LVItemCount,Dim2X+6]) ; iOrder
   ;-----------------------------------------------------------------------------------

   DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_INSERTCOLUMNA,long:ColX,lpbinary:LVCOLUMN)

   ColX = ColX + 1
EndWhile
BinaryFree(LVCOLUMN)

ItemX = 0
LVITEM=BinaryAlloc(40)          ; Create buffer for LVITEM structure

While ItemX < LVItemCount
   DllCall(user32,long:"SendMessageA",long:hProgBar,long:PBM_STEPIT,long:0,long:0) ; increment the progress bar
   ColX = 0
   ;-----Make LVItem structure for actual Items----------------------------------------------------
   BinaryPoke4(LVITEM,0,LVLoad[ItemX,ColX])  ; mask
   BinaryPoke4(LVITEM,4,ItemX)     ; iItem
   BinaryPoke4(LVITEM,8,0)         ; iSubitem  // YOU CANNOT USE INSERTITEM to INSERT SUBITEMS - the value must be 0 - (use SETITEM to insert subitem values)
   BinaryPoke4(LVITEM,12,LVLoad[ItemX,ColX+1])   ; state
   BinaryPoke4(LVITEM,16,LVLoad[ItemX,ColX+1])   ; stateMask
   BinaryPokeStr(TextBuf,0,LVLoad[ItemX,ColX+2]) ; Poke the text string into the buffer
   BinaryPoke(TextBuf,StrLen(LVLoad[ItemX,ColX+2]),0) ; Terminate buffer with a NULL
   BinaryPoke4(LVITEM,20,TextAd)                 ; pszText
   ;BinaryPoke4(LVITEM,24,255)                    ; cchTextMax ~ It is ignored when the structure specifies item attributes
   BinaryPoke4(LVITEM,28,LVLoad[ItemX,ColX+3])   ; iImage
   BinaryPoke4(LVITEM,32,LVLoad[ItemX,ColX+4])   ; lParam
   BinaryPoke4(LVITEM,36,LVLoad[ItemX,ColX+5])   ; iIndent ~ only works for Items not SubItems
   ;------------------------------------------------------------------------------
   InsertedItemX = DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_INSERTITEMA,long:0,lpbinary:LVITEM) ; Returns the actual Inserted Index - if the ListView has AutoSort styles on, the index might not be what we requested it to be
   ColX = 1
   While ColX < LVColCount
       Dim2X = ColX*10
       ;-----Make LVItem structure for SubItems----------------------------------------------------
       BinaryPoke4(LVITEM,0,LVLoad[ItemX,Dim2X])      ; mask - don't include lParam or iIndent for SubItems
       ;Message("Mask",LVLoad[ItemX,Dim2X])
       BinaryPoke4(LVITEM,4,InsertedItemX)      ; iItem  USING THE RETURNED ITEM INDEX FROM ABOVE
       BinaryPoke4(LVITEM,8,ColX)       ; iSubitem
       ;BinaryPoke4(LVITEM,12,LVLoad[ItemX,Dim2X+1])   ; state
       ;BinaryPoke4(LVITEM,12,LVLoad[ItemX,Dim2X+1])   ; state
       ;BinaryPoke4(LVITEM,16,LVLoad[ItemX,Dim2X+1])   ; stateMask
       BinaryPokeStr(TextBuf,0,LVLoad[ItemX,Dim2X+2]) ; Poke the text string into the buffer
       BinaryPoke(TextBuf,StrLen(LVLoad[ItemX,Dim2X+2]),0) ; Terminate buffer with a NULL
       BinaryPoke4(LVITEM,20,TextAd)                  ; pszText
       ;BinaryPoke4(LVITEM,24,255)                     ; cchTextMax ~ It is ignored when the structure specifies item attributes
       BinaryPoke4(LVITEM,28,LVLoad[ItemX,Dim2X+3])   ; iImage
       ;BinaryPoke4(LVITEM,32,LVLoad[ItemX,Dim2X+4])   ; lParam ~ Not for SubItems
       ;BinaryPoke4(LVITEM,36,0)                       ; iIndent ~ only works for Items not SubItems
       ;------------------------------------------------------------------------------
       DllCall(user32,long:"SendMessageA",long:hListView,long:LVM_SETITEMA,long:0,lpbinary:LVITEM)
       ColX = ColX + 1
   EndWhile
   ItemX = ItemX + 1
EndWhile
DllCall(user32,long:"DestroyWindow",long:hProgBar) ; destroy the progress bar
BinaryFree(TextBuf)
BinaryFree(LVITEM)
Return ItemX - 1
#EndFunction
;##########################################################################################################################################


Image List UDFs

;Note: not finished .. some documentation needs to be completed and cleaned up

;-----------------------------------------------------------------------------------------------------------------------------------------;
;CreateImageList : Creates an ImageList.   (See Microsoft Developer site for detailed information regarding ImageLists)                   ;
;v1.0 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;cx       : Width, in pixels, of each image.                                                                                              ;
;cy       : Height, in pixels, of each image.                                                                                             ;
;flags    : Set of bit flags that specify the type of image list to create.                                                               ;
;           This parameter can be a combination (Bitwise OR) of the following values, BUT it can include only one of the ILC_COLOR values.;
;             ILC_COLOR = 0       Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is  ;
;                                 ILC_COLOR4, but for older display drivers, the default is ILC_COLORDDB.                                 ;
;             ILC_COLOR4 = 4      Use a 4-bit (16-color) device-independent bitmap (DIB) section as the bitmap for the image list.        ;
;             ILC_COLOR8 = 8      Use an 8-bit DIB section. Colors used for the color table are the same colors as the halftone palette.  ;
;             ILC_COLOR16 = 16    Use a 16-bit (32/64k-color) DIB section.                                                                ;
;             ILC_COLOR24 = 24    Use a 24-bit DIB section.                                                                               ;
;             ILC_COLOR32 = 32    Use a 32-bit DIB section.                                                                               ;
;             ILC_COLORDDB = 254  Use a device-dependent bitmap.                                                                          ;
;             ILC_MASK = 1        Use a mask. The image list contains two bitmaps, one of which is a monochrome bitmap used as a mask.    ;
;                                 If this value is not included, the image list contains only one bitmap.                                 ;
;                          NOTE : There are a couple of mirror flag values for right-to-left screens as used by some languages such as    ;
;                                 Hebrew or Arabic, but they require a specific call to version 6 or above of comctl32.dll and so I have  ;
;                                 not included them here.                                                                                 ;
;cInitial : Number of images that the image list initially contains.                                                                      ;
;cGrow    : Number of images by which the image list can grow when the system needs to make room for new images.                          ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns  : The handle to the image list if successful, or NULL otherwise.                                                                ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction ILCreate(cx,cy,flags,cInitial,cGrow)
comctl32=StrCat(DirWindows(1),"comctl32.dll")
Return DllCall(comctl32,long:"ImageList_Create",long:cx,long:cy,long:flags,long:cInitial,long:cGrow)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;ILAdd : Add to an ImageList.                                                                                                             ;
;v1.0 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;himl      : Handle to the image list.                                                                                                    ;
;hbmImage  : Handle to the bitmap that contains the image or images. The number of images is inferred from the width of the bitmap.       ;
;hbmMask   : Handle to the bitmap that contains the mask. If no mask is used with the image list, this parameter is ignored.              ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : The index of the first new image if successful, or -1 otherwise.                                                             ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction ILAdd(himl,hbmImage,hbmMask)
comctl32 = StrCat(DirWindows(1),"comctl32.dll")
gdi32 = StrCat(DirWindows(1),"gdi32.dll")
index = DllCall(comctl32,long:"ImageList_Add",long:himl,long:hbmImage,long:hbmMask);Copies the bitmap to an internal data structure.
DllCall(gdi32,long:"DeleteObject",long:hbmImage);Delete hbmImage and hbmMask after the function returns.
Return index
#EndFunction
;##########################################################################################################################################

;-----------------------------------------------------------------------------------------------------------------------------------------;
;ILDraw : Directly draw an icon from an imagelist onto a DeviceContext (usually a screen window).                                         ;
;v1.0 by IFICantBYTE (2012)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;himl,i,hdcDst,x,y,dx,dy,rgbBk,rgbFg,fStyle
;comments not finished here yet
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : Bool 1 (TRUE) on success 0 (FALSE) if failed.
;-----------------------------------------------------------------------------------------------------------------------------------------;
;!!!!!!!!! TO DO... Clean up documentation and comments

;fStyle
;Type: UINT
;
;The drawing style and, optionally, the overlay image. For information about specifying an overlay image index, see the comments section at the end of this topic. This parameter can be a combination of an overlay image index and one or more of the following values:
;
;
;Value
;
;Meaning
;
;
;ILD_BLEND25,
;
;ILD_FOCUS
;
;Draws the image, blending 25 percent with the system highlight color. This value has no effect if the image list does not contain a mask.
;
;ILD_BLEND50,
;
;ILD_SELECTED,
;
;ILD_BLEND
;
;Draws the image, blending 50 percent with the system highlight color. This value has no effect if the image list does not contain a mask.
;
;ILD_MASK
;
;Draws the mask.
;
;ILD_NORMAL
;
;Draws the image using the background color for the image list. If the background color is the CLR_NONE value, the image is drawn transparently using the mask.
;
;ILD_TRANSPARENT
;
;Draws the image transparently using the mask, regardless of the background color. This value has no effect if the image list does not contain a mask.


#DefineFunction ILDraw(himl,i,hdcDst,x,y,dx,dy,rgbBk,rgbFg,fStyle)
comctl32 = StrCat(DirWindows(1),"comctl32.dll")
user32 = StrCat(DirWindows(1),"user32.dll")

;gdi32 = strcat(dirwindows(1),"gdi32.dll")
hdc=DllCall(user32,long:"GetDC",long:hdcDst);get the DC of the drawing device - usually a window on the screen, but could be something else
r1 = ItemExtract(1,rgbBk,"|")
g1 = ItemExtract(2,rgbBk,"|")
b1 = ItemExtract(3,rgbBk,"|")
COLOUR1 = b1*256*256 + g1*256 + r1
r2 = ItemExtract(1,rgbFg,"|")
g2 = ItemExtract(2,rgbFg,"|")
b2 = ItemExtract(3,rgbFg,"|")
COLOUR2 = b2*256*256 + g2*256 + r2
ret = DllCall(comctl32,long:"ImageList_DrawEx",long:himl,long:i,long:hdc,long:x,long:y,long:dx,long:dy,long:COLOUR1,long:COLOUR2,long:fStyle)
;dllcall(gdi32,long:"DeleteObject",long:hbmImage);Delete hbmImage and hbmMask after the function returns.
Return ret
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;ILGetIcon : Get an icon handle from an ImageList.
;v1.0 by IFICantBYTE (2012)
;-----------------------------------------------------------------------------------------------------------------------------------------;
;himl      : Handle to the image list.
;i         : Index of the icon within the image list. (0 is first one)
;flags     : A combination of flags that specify the drawing style. For a list of values, see the description of the fStyle parameter of the ImageList_Draw function.
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : Returns the handle to the icon if successful, or NULL otherwise.
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction ILGetIcon(himl,i,flags)
comctl32 = StrCat(DirWindows(1),"comctl32.dll")
Return DllCall(comctl32,long:"ImageList_GetIcon",long:himl,long:i,long:flags)
#EndFunction
;##########################################################################################################################################


;----------------------------------------------------------------------------
;DrawIcon : Draws an icon using a static control on a window.
;----------------------------------------------------------------------------
;hdlg     : dialog handle
;x        : x position in pixels inside the hWin to draw the icon
;y        : y position in pixels inside the hWin to draw the icon
;hIcon    : an existing icon handle
;----------------------------------------------------------------------------
;Returns  : handle of the new static control used for the icon.
;----------------------------------------------------------------------------
#DefineFunction DrawIcon(hWin,x,y,hIcon)
user32=StrCat(DirWindows(1),"user32.dll")

WS_CHILD=1073741824
WS_VISIBLE=268435456
SS_ICON=3
STM_SETICON=368

;get icon handle
;hicon=dllcall(user32,long:"LoadIconA",lpnull,long:icontype)

;static control
hStatic=DllCall(user32,long:"CreateWindowExA",long:0,lpstr:"Static",lpstr:"",long:WS_CHILD|WS_VISIBLE|SS_ICON,long:x,long:y,long:0,long:0,long:hWin,long:0,long:DllHinst(""),long:0)

;set icon
DllCall(user32,long:"SendMessageA",long:hstatic,long:STM_SETICON,long:hIcon,long:0)
Return hStatic
#EndFunction
;##########################################################################################################################################



;-----------------------------------------------------------------------------------------------------------------------------------------------;
; See LoadImage ... very similar, but you dont need to add this pic to a pre made IL - this does it in one go, but can have slightly different colour results - choose what looks best to you
;-----------------------------------------------------------------------------------------------------------------------------------------------;
;hinst     : Handle to an instance of the module that contains the image to be loaded (if in a DLL or something).                         ;
;            To load an OEM image, set this parameter to zero.                                                                            ;
;lpszName  : The image to load. Unicode strings are supported on Microsoft Windows NT 4.0, Windows 2000, and later, but they are not supported on Windows 95 and Windows 98.
;            If the uFlags parameter includes LR_LOADFROMFILE, lpbmp is the address of a null-terminated string that names the file containing the image to load.
;            If the hinst parameter is non-NULL and LR_LOADFROMFILE is not specified, lpbmp is the address of a null-terminated string that contains the name of the image resource in the hinst module.
;            If hinst is NULL and LR_LOADFROMFILE is not specified, the LOWORD of this parameter must be the identifier of an OEM image to load. To create this value, use the MAKEINTRESOURCE macro with one of the OEM image identifiers defined in Winuser.h. These identifiers have the following prefixes.
;            OBM_ for OEM bitmaps   OIC_ for OEM icons   OCR_ for OEM cursors
;cx        : The width of each image. The height of each image and the initial number of images are inferred by the dimensions of the specified resource.
;cGrow     : The number of images by which the image list can grow when the system needs to make room for new images. This parameter represents the number of new images that the resized image list can contain.
;crMask    : The color used to generate a mask. Each pixel of this color in the specified bitmap, cursor, or icon is changed to black, and the corresponding bit in the mask is set to 1. If this parameter is the CLR_NONE value, no mask is generated. If this parameter is the CLR_DEFAULT value, the color of the pixel at the upper-left corner of the image is treated as the mask color.
;            CLR_NONE = 4294967295 - will be used if a string "CLR_NONE" is passed
;            CLR_DEFAULT = 4278190080 - will be used if any other non integer (string) is passed
;cFlags    : Flags that specify how to load the image. This parameter can be a combination of the following values.
;            LR_CREATEDIBSECTION = 8192 Causes the function to return a DIB section bitmap rather than a compatible bitmap when the uType parameter specifies IMAGE_BITMAP. LR_CREATEDIBSECTION is useful for loading a bitmap without mapping it to the colors of the display device.
;            LR_DEFAULTCOLOR     = 0     Uses the color format of the display.
;            LR_DEFAULTSIZE      = 64    Uses the width or height specified by the system metric values for cursors and icons if the cx parameter is set to zero. If this value is not specified and cx is set to zero, the function sets the size to the one specified in the resource. If the resource contains multiple images, the function sets the size to that of the first image.
;            LR_LOADFROMFILE     = 16    Loads the image from the file specified by the lpbmp parameter.
;            LR_LOADMAP3DCOLORS  = 4096  Searches the color table for the image and replaces the following shades of gray with the corresponding three-dimensional color:
;                                        Dk Gray: RGB(128, 128, 128)COLOR_3DSHADOW   Gray: RGB(192, 192, 192)COLOR_3DFACE   Lt Gray: RGB(223, 223, 223)COLOR_3DLIGHT  For more information, see the Remarks section.
;            LR_LOADTRANSPARENT  = 32    Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (the COLOR_WINDOW display color). All pixels in the image that use that color become the default window value color. This value applies only to images that have a corresponding color table. For more information, see the Remarks section.
;            LR_MONOCHROME       = 1     Loads the image in black and white.
;            LR_SHARED           = 32768 Shares the image handle if the image is loaded multiple times. Do not use this value for images that have nontraditional sizes that might change after loading or for images that are loaded from a file.
;-----------------------------------------------------------------------------------------------------------------------------------------------;
;Returns   : The handle to the image list if successful, or NULL otherwise.
;-----------------------------------------------------------------------------------------------------------------------------------------------;
;Remarks   : LR_LOADTRANSPARENT does not load the image transparently. It creates an opaque image list that only appears transparent because all the background pixels have been changed to COLOR_WINDOW. If the images are drawn over a background that is not the color COLOR_WINDOW, the image does not draw properly. Also, LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS use the system colors that were in effect at the time that ImageList_LoadImage was called. If the system colors subsequently change, the application must reload the image to remap the colors.
;-----------------------------------------------------------------------------------------------------------------------------------------------;

#DefineFunction ILLoadImage(hinst,lpszName,cx,cGrow,crMask,cFlags)
comctl32=StrCat(DirWindows(1),"comctl32.dll")
uType = 0;BMP only supported according to MS http://msdn.microsoft.com/en-us/library/windows/desktop/bb761557(v=vs.85).aspx
If crMask == "CLR_NONE" Then crMask = 4294967295
If IsInt(crMask) == @FALSE Then crMask = 4278190080 ; CLR_DEFAULT
Return DllCall(comctl32,long:"ImageList_LoadImageA",long:hinst,lpstr:lpszName,long:cx,long:cGrow,long:crMask,long:uType,long:cFlags)
#EndFunction
;##########################################################################################################################################


;-----------------------------------------------------------------------------------------------------------------------------------------;
;LoadImage : Load an Image into memory.                                                                                                   ;
;v1.1 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hinst     : Handle to an instance of the module that contains the image to be loaded.                                                    ;
;            To load an OEM image, set this parameter to zero.                                                                            ;
;lpszName  : Specifies the image to load.                                                                                                 ;
;            If hinst is non-NULL and fuLoad omits LR_LOADFROMFILE, lpszName specifies the image resource in the hinst module.            ;
;            If the image resource is to be loaded by name, then lpszName is a pointer to a null-terminated string that contains the name ;
;            of the image resource.                                                                                                       ;
;            If the image resource is to be loaded by ordinal, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function.
;
;            If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image
;            to load.
;            The OEM image identifiers are defined in Winuser.h and have the following prefixes.
;
;            OBM_ OEM bitmaps
;            OIC_ OEM icons
;            OCR_ OEM cursors
;
;            [ To pass these constants to the LoadImage function, use the MAKEINTRESOURCE macro.                                            ]
;            [ For example, to load the OCR_NORMAL cursor, pass MAKEINTRESOURCE(OCR_NORMAL) as the lpszName parameter and NULL as the hinst ]
;            [ parameter. (This is talking about MSD VB&.NET environment not Winbatch, but taken from MSD web site for info purposes)       ]
;
;            If the fuLoad parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the image.
;
;uType     : The type of image to be loaded. This parameter can be one of the following values.
;            IMAGE_BITMAP = 0 Loads a bitmap.
;            IMAGE_CURSOR = 2 Loads a cursor.
;            IMAGE_ICON = 1 Loads an icon.
;cxDesired : The width, in pixels, of the icon or cursor.
;            If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system
;            metric value to set the width.
;            If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.
;cyDesired : The height, in pixels, of the icon or cursor.
;            If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system
;            metric value to set the height.
;            If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.
;fuLoad    : This parameter can be one or more of the following values:
;            LR_DEFAULTCOLOR = 0        The default flag - it does nothing. All it means is "not LR_MONOCHROME".
;            LR_CREATEDIBSECTION = 8192 When the uType parameter specifies IMAGE_BITMAP, causes the function to return a DIB section bitmap
;                                       rather than a compatible bitmap. This flag is useful for loading a bitmap without mapping it to the
;                                       colors of the display device.
;            LR_DEFAULTSIZE = 64        Uses the width or height specified by the system metric values for cursors or icons, if the
;                                       cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and
;                                       cyDesired are set to zero, the function uses the actual resource size.
;                                       If the resource contains multiple images, the function uses the size of the first image.
;            LR_LOADFROMFILE = 16       Loads the image from the file specified by the lpszName parameter. If this flag is not specified,
;                                       lpszName is the name of the resource.
;            LR_LOADMAP3DCOLORS = 4096  Searches the color table for the image and replaces the following shades of gray with the
;                                       corresponding 3-D color:
;                                       Color Replaced with
;                                       Dk Gray, RGB(128,128,128) COLOR_3DSHADOW
;                                       Gray, RGB(192,192,192) COLOR_3DFACE
;                                       Lt Gray, RGB(223,223,223) COLOR_3DLIGHT
;                                NOTE : Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.
;            LR_LOADTRANSPARENT = 32    Retrieves the color value of the first pixel in the image and replaces the corresponding entry in
;                                       the color table with the default window color (COLOR_WINDOW).
;                                       All pixels in the image that use that entry become the default window color. This value applies
;                                       only to images that have corresponding color tables.
;                                NOTE : Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.
;
;                                NOTE : If fuLoad includes both the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS values, LRLOADTRANSPARENT
;                                       takes precedence.
;                                       However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.
;
;            LR_MONOCHROME = 1          Loads the image in black and white.
;            LR_SHARED = 32768          Shares the image handle if the image is loaded multiple times.
;                                       If LR_SHARED is not set, a second call to LoadImage for the same resource will load the image again
;                                       and return a different handle.
;                                       When you use this flag, the system will destroy the resource when it is no longer needed.
;                                NOTE : Do not use LR_SHARED for images that have non-standard sizes, that may change after loading,
;                                       or that are loaded from a file.
;                                       BUT when loading a system icon or cursor, you MUST use LR_SHARED or the function will fail to load
;                                       the resource.
;                                       Under Windows 95/98/Me: The function finds the first image with the requested resource name in the
;                                       cache, regardless of the size requested.
;
;            LR_VGACOLOR = 128          Uses true VGA colors.
;-----------------------------------------------------------------------------------------------------------------------------------------------
;Returns   : Handle of the newly loaded image if successful or NULL otherwise.
;-----------------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction LoadImage(hinst,lpszName,uType,cxDesired,cyDesired,fuLoad)
user32=StrCat(DirWindows(1),"user32.dll")
;lpszName = "ico16x16.bmp"
;return dllcall(user32,long:"LoadImageA",long:0,lpstr:lpszName,long:0,long:0,long:0,long:16|64) ; Typical load from file in one go
Return DllCall(user32,long:"LoadImageA",long:hinst,lpstr:lpszName,long:uType,long:cxDesired,long:cyDesired,long:fuLoad)
#EndFunction
;##########################################################################################################################################



ReportView With Image Sample

;this is a thrown-together example of how you can set icons and formatting to help indicate the difference between items in a listview (ReportView control) using DLL calls


uselessinfo = ArrayFileGetCSV("uselessinfo.csv",0)


;-----------------------------------------------------------------------------------------------------------------------------------------;
;GetMouseWinCoordinates : Get a Window's client-area coordinates where the mouse currently is                                             ;
;v1.0 by IFICantBYTE (2004)                                                                                                               ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;hWindow : Window handle we want to get the relative client-area mouse coordinates for                                                    ;
;delim   : The delimiter you want to use between the returned X and Y values - eg: "," or @TAB or @CRLF or " " (space)                    ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
;Returns : Returns a delimited string containing the current mouse X and Y coordinates (Windows' pixels - not Winbatch's 1K units)        ;
;          relative to the Window specified by the handle.                                                                                ;
;   NOTE : 0 0 is top Left corner. Values can go into negatives and the window specified does not have to be the topmost, active or       ;
;          focused. This will not return correct results with a mirrored Window using a Right to Left ExStyle                             ;
;-----------------------------------------------------------------------------------------------------------------------------------------;
#DefineFunction GetMouseWinCoordinates(hWindow,delim)
user32=StrCat(DirWindows(1),"user32.dll")
ParseData(MouseInfo(3)) ; Get the current mouse position relative to the windows desktop at its current pixel resolution
                        ; and parse it out to variables param1 and param2
   ;----- Make POINT structure --------------------------------------------
   POINTINFO=BinaryAlloc(8)        ; Create buffer for structure
   BinaryPoke4(POINTINFO,0,param1) ; Initially contains our X coordinate based on Desktop - after dll call it will contain
                                   ; converted X coord. relative to window specified (starting from 0 in top left corner)
   BinaryPoke4(POINTINFO,4,param2) ; As above but for Y coordinate
   ;-----------------------------------------------------------------------
DllCall(user32,long:"ScreenToClient",long:hWindow,lpbinary:POINTINFO)
x = BinaryPeek4(POINTINFO,0)
y = BinaryPeek4(POINTINFO,4)
BinaryFree(POINTINFO)
Return StrCat(x,delim,y)
#EndFunction
;##########################################################################################################################################


;============================================================
;============================================================
;============================================================




#DefineSubRoutine InitDialogConstants()
   ;DialogprocOptions Constants
   MSG_INIT=0                    ; The one-time initialization
   MSG_TIMER=1                   ; Timer event
   MSG_BUTTONPUSHED=2            ; Pushbutton or Picturebutton
   MSG_RADIOPUSHED=3             ; Radiobutton clicked
   MSG_CHECKBOX=4                ; Checkbox clicked
   MSG_EDITBOX=5                 ; Editbox or Multilinebox
   MSG_FILESELECT=6              ; Filelistbox
   MSG_ITEMSELECT=7              ; Itembox
   MSG_COMBOCHANGE=8             ; Combobox/Droplistbox
   MSG_CALENDAR=9                ; Calendar date change
   MSG_SPINNER=10                ; Spinner number change
   MSG_CLOSEVIA49=11             ; Close clicked (Enabled via DialogProcOptions 1002
   MSG_FILEBOXDOUBLECLICK=12     ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13     ; Get double-click message on an ItemBox
   MSG_COMEVENT=14               ; COMCONTROL Event notification from DialogObject (NOT DialogProcOptions)
   MSG_MENUITEM=15               ; MenuItem selected
   MSG_MENUITEMINIT=16           ; MenuItem initialized
   MSG_RESIZE=17                 ; Dialog resized
   MSG_RVITEMSELROW=18           ; Reportview item select row
   MSG_RVDBLCLICKROW=19          ; Reportview double-click row
   MSG_RVCHECKEDITEM=20          ; Reportview checked/unchecked Item
   MSG_RVITEMTEXT=21             ; Reportview changed text of first column
   MSG_RVHEADER=22               ; Reportview header clicked

   DPO_DISABLESTATE=1000         ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog
   DPO_CHANGEBACKGROUND=1001     ; -1=Get Current otherise bitmap or color string
   DPO_CHANGESYSMENU=1002        ; -1=Get Current 0=none 1=close 2=close/min 3=close/max 4=close/min/max
   DPO_CHANGETITLE=1003          ; Set/Get Dialog Title - (-1 to get)
   DPO_GETNAME=1004              ; Returns the name associated with a control's number.
   DPO_GETNUMBER=1005            ; Returns the number associated with a control's name.
   DPO_GETCLIENTAREA=1007        ; Returns a space delimited list of the width and height of the client area.

   ;DialogControlState Constants
   DCSTATE_SETFOCUS=1            ; Give Control Focus
   DCSTATE_QUERYSTYLE=2          ; Query control's style
   DCSTATE_ADDSTYLE=3            ; Add control style
   DCSTATE_REMOVESTYLE=4         ; Remove control style
   DCSTATE_GETFOCUS=5            ; Get control that has focus
   DCSTATE_MOVEMOUSEOVER=6       ; Move the mouse over the control

   DCSTYLE_DEFAULT=0             ; Set Default Style
   DCSTYLE_INVISIBLE=1           ; Set Control Invisible
   DCSTYLE_DISABLED=2            ; Set Control Disabled
   DCSTYLE_NOUSERDATA=4          ; Note: Setable via DialogControlState function ONLY SPINNER control only
   DCSTYLE_READONLY=8            ; Sets control to read-only (user cannot type in data) EDITBOX MULTILINEBOX SPINNER
   DCSTYLE_PASSWORD=16           ; Sets 'password mode' where only *'s are displayed EDITBOX
   DCSTYLE_DEFAULTBUTTON=32      ; Sets a button as the default button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_DIGITSONLY=64         ; Set edit box to accept digits only EDITMOX MULTILINEBOX
   DCSTYLE_FLAT=128              ; Makes a 'flat' hyperlink-looking button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_NOADJUST=256          ; Turns off auto-height adjustment  ITEMBOX FILELISTBOX
   DCSTYLE_TEXTCENTER=512        ; Center text in control VARYTEXT STATICTEXT
   DCSTYLE_TEXTRIGHT=1024        ; Flush-Right text in control VARYTEXT STATICTEXT
   DCSTYLE_NOSELCURLEFT=2048     ; No selection, cursor left EDITBOX MULTILINEBOX
   DCSTYLE_NOSELCURRIGHT=4096    ; No selection, cursor right EDITBOX MULTILINEBOX
   DCSTYLE_SHIELD=8192           ; Display Security Shield icon on button (Vista only) PUSHBUTTON PICTUREBUTTON
   DCSTYLE_MENUCHECK=32768       ; Adds a check mark to the left of a menu item MENUITEM
   DCSTYLE_MENURADIO=65536       ; Adds a radio button like dot graphic to the left of a menu item MENUITEM
   DCSTYLE_MENUSEP=131072        ; Separator bar graphic MENUITEM
   DCSTYLE_MENUBREAK=262144      ; Column break MENUBAR
   DCSTYLE_NOHEADER=524288       ; No header bar REPORTVIEW
   DCSTYLE_COLHEADER=1048576     ; First row column header REPORTVIEW
   DCSTYLE_GRIDLINES=2097152     ; Grid lines REPORTVIEW
   DCSTYLE_SELONEROW=4194304     ; Only one row can be selected at a time REPORTVIEW
   DCSTYLE_SELALLROW = 8388608   ; Highlight complete row REPORTVIEW
   DCSTYLE_SORTASC=16777216      ; Ascending sort REPORTVIEW
   DCSTYLE_SORTDESC=33554432     ; Descending sort REPORTVIEW
   DCSTYLE_EDITCOL=67108864      ; Edit first columns text REPORTVIEW
   DCSTYLE_COLCHECKBOX=134217728 ; Add checkbox to first column REPORTVIEW

   ;DialogControlSet / DialogControlGet Constants
   DC_CHECKBOX=1             ; CHECKBOX REPORTVIEW
   DC_RADIOBUTTON=2          ; RADIOBUTTON
   DC_EDITBOX=3              ; EDITBOX MULTILINEBOX
   DC_TITLE=4                ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON MENUITEM
   DC_ITEMBOXCONTENTS=5      ; ITEMBOX FILELISTBOX DROPLISTBOX REPORTVIEW
   DC_ITEMBOXSELECT=6        ; ITEMBOX FILELISTBOX DROPLISTBOX REPORTVIEW
   DC_CALENDAR=7             ; CALENDAR
   DC_SPINNER=8              ; SPINNER
   DC_MULTITABSTOPS=9        ; MULTILINEBOX
   DC_ITEMSCROLLPOS=10       ; ITEMBOX FILELISTBOX
   DC_BACKGROUNDCOLOR=11     ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX REPORTVIEW
   DC_PICTUREBITMAP=12       ; PICTURE PICTUREBUTTON
   DC_TEXTCOLOR=13           ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX REPORTVIEW
   DC_ITEMBOXADD=14          ; ITEMBOX FILELISTBOX DROPLISTBOX REPORTVIEW
   DC_ITEMBOXREMOVE=15       ; ITEMBOX FILELISTBOX DROPLISTBOX REPORTVIEW
   DC_RADIOVALUE=16          ; RADIOBUTTON
   DC_POSITION=17            ; ALL CONTROLS (Except MENUBAR and MENUITEM)
   DC_MENUNAMES=18           ; ALL CONTROLS
   DC_HANDLE=19              ; ALL CONTROLS (Except MENUBAR and MENUITEM)
   DC_RVCOLHEAD=20           ; REPORTVIEW
   DC_RVCOLWIDTH=21          ; REPORTVIEW
   DC_RVADDCOL=22            ; REPORTVIEW
   DC_RVREMOVECOL=23         ; REPORTVIEW
   DC_RVMATCHCOL=24          ; REPORTVIEW
   DC_RVCANCELEDIT=25        ; REPORTVIEW
   DC_RVCHECKEDROWS=26       ; REPORTVIEW
   DC_RVJUSTIFY=27           ; REPORTVIEW


   ;DialogObject constants
   DLGOBJECT_ADDEVENT=1      ; Call dialog callback when the specified event occurs
   DLGOBJECT_STOPEVENT=2     ; Stop calling dialog callback when an event previously requested with
   DLGOBJECT_GETOBJECT=3     ; Return an object references to the specified control
   DLGOBJECT_GETPICTURE=4    ; Create and return an object reference to a picture object

   ;Return code constants
   RET_DO_CANCEL=0           ; Cancels dialog
   RET_DO_DEFAULT= -1        ; Continue with default processing for control
   RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
   Return
#EndSubRoutine
;============================================================
;============================================================
;============================================================





InitDialogConstants()                                       ; Initialize Dialog Constants (need only be done once usually)

#DefineSubRoutine RVDlgCallbackProc(RVDlg_Handle,RVDlg_Message,RVDlg_Name,RVDlg_EventInfo,RVDlg_ChangeInfo)
   ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
   Switch RVDlg_Message                                  ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
         DialogProcOptions(RVDlg_Handle,MSG_TIMER,200)
         DialogProcOptions(RVDlg_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(RVDlg_Handle,MSG_RVITEMSELROW,@TRUE)
;         DialogProcOptions(RVDlg_Handle,MSG_RVDBLCLICKROW,@TRUE)
;         DialogProcOptions(RVDlg_Handle,MSG_RVCHECKEDITEM,@TRUE)
;         DialogProcOptions(RVDlg_Handle,MSG_RVITEMTEXT,@TRUE)
;         DialogProcOptions(RVDlg_Handle,MSG_RVHEADER,@TRUE)
    DialogControlSet(RVDlg_Handle,"ReportView_1",DC_ITEMBOXCONTENTS,uselessinfo)
    DialogControlSet(RVDlg_Handle,"ReportView_1",DC_RVCOLHEAD,"First useless info column":@TAB:"Second":@TAB:"Third":@TAB:"Meaningless numbers":@TAB:"Stupid associations":@TAB:"Last useless info column")
    DialogControlSet(RVDlg_Handle,"ReportView_1",DC_RVCOLWIDTH,"105 85 85 85 85 85")
    hRVCtl = DialogControlGet(RVDlg_Handle,"ReportView_1",19);Get the Window handle of the ReportView control
         Return(RET_DO_DEFAULT)

     Case MSG_TIMER                ; TimerEvent
ParseData(GetMouseWinCoordinates(hRVCtl," "))
;message("HitTest",LVItemHitTest(hRVCtrl,Param1,Param2,","))
DialogControlSet(RVDlg_Handle,"VaryText_1", 4, LVItemHitTest(hRVCtl,Param1,Param2,",") )
     Return(RET_DO_DEFAULT)


     Case MSG_BUTTONPUSHED
        If RVDlg_Name == "PushButton_OK"                ; OK

;make a valid image list - I use my old UDFs to do it from one resource bmp.
hILMain16x16 = ILLoadImage(0,"imglst16x16.bmp",16,16,"CLR_DEFAULT",8192|16|32|64); - have to have ind DIB 8192 on or colours get remapped to nearest and don't look as good
LVSetImageList(hRVCtl,1,hILMain16x16) ; Assign the imagelist to the listview control as "smallicons" for 16x16pixel REPORT, SMALLICON and LIST modes
;CurrentExStyle = LVGetExtendedStyle(hRVCtl)
LVSetExtendedStyle(hRVCtl,2,2) ; Turn on LVS_EX_SUBITEMIMAGES extended style style so we can see the subitems with icons when the dialog starts

;Set some icons, states stuff to items:
;LVSetItem(hListView,iItem,iSubItem,text,iImage,lParam,iIndent,mask)
;NOTE: ITEM INDEX IS REALLY ZERO BASED - so first item is 0, second item index is 1 etc.
LVSetItem(hRVCtl,0,0,0,1,0,0,2);Set first item (zero based) icon to the second (index 1) icon in the image list (....IFICantBYTE)
LVSetItem(hRVCtl,1,0,0,-1,0,0,2);Set second item (zero based) icon to an invalid one to 'clear' it (WB's new RV control seems to set icon to 0 for all as default)
LVSetItem(hRVCtl,2,0,0,6,0,5,2|16);Set the icon to image 6 and the indent to 5 icon widths for the third item (mask 2|16 is icon|indent)
LVSetItem(hRVCtl,4,0,0,4,0,0,2);Set 5th item's icon to the 5th in the image list
LVSetItem(hRVCtl,5,0,0,2,0,0,2)
LVSetItem(hRVCtl,7,4,0,14,0,0,2);Set the 8th items' subitem in the 5th column to the 15th icon in the imagelist
LVSetItem(hRVCtl,8,5,0,15,0,0,2)
LVSetItem(hRVCtl,9,1,0,13,0,0,2)


Col3List = LVGetColumn(hRVCtl,2,@TAB);Get current info about column 3 to use again later (really column index 2 because it's zero based like items)
Col5List = LVGetColumn(hRVCtl,4,@TAB)

;LVSetColumn(hListView,iCol,mask,frmt,cx,text,iSubItem,iImage,iOrder)
;See Microsoft LVCFMT_ values etc.
;Give 3rd header column the correct format to use an icon, set one and also change the heading text, but keep everything else the same
LVSetColumn(hRVCtl,2,ItemExtract(1,Col3List,@TAB)|1|16,ItemExtract(2,Col3List,@TAB)|2048|32768,ItemExtract(3,Col3List,@TAB),"Third Now with icon!",ItemExtract(5,Col3List,@TAB),12,ItemExtract(7,Col3List,@TAB))
;Give 5th header an icon and make it go to the right of the text (4096), also give whole column Center formatting (2)
LVSetColumn(hRVCtl,4,ItemExtract(1,Col5List,@TAB)|1|16,ItemExtract(2,Col5List,@TAB)|2|2048|4096|32768,ItemExtract(3,Col5List,@TAB),ItemExtract(4,Col5List,@TAB),ItemExtract(5,Col5List,@TAB),7,ItemExtract(7,Col5List,@TAB))


;LVSetItemState(hListView,iItem,state,stateMask)
LVSetItemState(hRVCtl,10,4,4);CUT
LVSetItemState(hRVCtl,11,8,8);DROPHILITED
LVSetHotItem(hRVCtl,12)

              Return(RET_DO_NOT_EXIT)

        ElseIf RVDlg_Name == "PushButton_Cancel"        ; Cancel
              Return(RET_DO_DEFAULT)

        EndIf                                              ; RVDlg_Name
        Return(RET_DO_DEFAULT)

;     case MSG_RVITEMSELROW                                 ; ID "ReportView_1"  rvVariable1
;        return(RET_DO_DEFAULT)

   EndSwitch                                                ; RVDlg_Message
   Return(RET_DO_DEFAULT)
#EndSubRoutine                                              ; End of Dialog Callback RVDlgCallbackProc

;============================================================
;============================================================
;============================================================

RVDlgFormat=`WWWDLGED,6.2`

RVDlgCaption=`Icon and item formatting example`
RVDlgX=400
RVDlgY=100
RVDlgWidth=564
RVDlgHeight=183
RVDlgNumControls=005
RVDlgProcedure=`RVDlgCallbackProc`
RVDlgFont=`DEFAULT`
RVDlgTextColor=`DEFAULT`
RVDlgBackground=`DEFAULT,DEFAULT`
RVDlgConfig=0

RVDlg001=`375,159,090,016,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK ...Show me the pretty version!",1,10,32,DEFAULT,DEFAULT,"128|255|128"`
RVDlg002=`515,161,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RVDlg003=`009,013,542,140,REPORTVIEW,"ReportView_1",rvVariable1,DEFAULT,DEFAULT,30,10485760,"Microsoft Sans Serif|6656|40|34","128|128|0","255|255|255"`
RVDlg004=`009,163,090,012,STATICTEXT,"StaticText_1",DEFAULT,"Mouse position HIT TEST results:",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
RVDlg005=`103,163,080,012,VARYTEXT,"VaryText_1",vtVariable1,"Vary 1",DEFAULT,50,DEFAULT,"Microsoft Sans Serif|6656|70|34","255|0|0",DEFAULT`

ButtonPushed=Dialog("RVDlg")


Article ID:   W16233
File Created: 2012:10:12:09:54:14
Last Updated: 2012:10:12:09:54:14