| 1 | ;~ #Include <GuiListView.au3>
|
|---|
| 2 | #include <WindowsConstants.au3>
|
|---|
| 3 | #Include <GUIConstantsEx.au3>
|
|---|
| 4 | #Include <WinAPI.au3>
|
|---|
| 5 | #Include <ListViewConstants.au3>
|
|---|
| 6 | #Include <GuiImageList.au3>
|
|---|
| 7 | #Include <string.au3>
|
|---|
| 8 |
|
|---|
| 9 | Opt("GUIOnEventMode", 1)
|
|---|
| 10 | $Debug_LV = 0
|
|---|
| 11 |
|
|---|
| 12 | $Gui = GUICreate("Test Alpha", 750, 590, 191, 113, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION))
|
|---|
| 13 |
|
|---|
| 14 | $hImage = _GUIImageList_Create(16, 16, 5, 3)
|
|---|
| 15 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
|
|---|
| 16 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
|
|---|
| 17 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
|
|---|
| 18 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
|
|---|
| 19 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
|
|---|
| 20 | _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | $ListView = GUICtrlCreateListView("text0 |text1|text2|text3", 8, 120, 121*3, 431, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_HEADERDRAGDROP, $LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_DOUBLEBUFFER,$LVS_EX_SUBITEMIMAGES))
|
|---|
| 24 |
|
|---|
| 25 | _GUICtrlListView_InsertItem($ListView, "TestText", 1)
|
|---|
| 26 |
|
|---|
| 27 | _GUICtrlListView_SetImageList($listview, $hImage, 1)
|
|---|
| 28 |
|
|---|
| 29 | GUISetState(@SW_SHOW,$GUI)
|
|---|
| 30 |
|
|---|
| 31 | GUISetOnEvent($GUI_EVENT_CLOSE, "Close",$GUI)
|
|---|
| 32 |
|
|---|
| 33 | GUICtrlSetState($listview, $GUI_FOCUS)
|
|---|
| 34 | Func Close()
|
|---|
| 35 | Exit
|
|---|
| 36 | EndFunc
|
|---|
| 37 |
|
|---|
| 38 | ConsoleWrite("-Start--Original UDF's ----" & @CRLF)
|
|---|
| 39 | Sleep(2000)
|
|---|
| 40 | _GUICtrlListView_SetItemCut($ListView, 0, True)
|
|---|
| 41 | ConsoleWrite("SetItemCut: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_CUT) & @CRLF)
|
|---|
| 42 | Sleep(2000)
|
|---|
| 43 | _GUICtrlListView_SetItemCut($ListView, 0, False)
|
|---|
| 44 | ConsoleWrite("SetItemCut: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_CUT) & @CRLF)
|
|---|
| 45 | Sleep(2000)
|
|---|
| 46 | _GUICtrlListView_SetItemDropHilited($ListView, 0, True)
|
|---|
| 47 | ConsoleWrite("SetItemDropHilited: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_DROPHILITED) & @CRLF)
|
|---|
| 48 | Sleep(2000)
|
|---|
| 49 | _GUICtrlListView_SetItemDropHilited($ListView, 0, False)
|
|---|
| 50 | ConsoleWrite("SetItemDropHilited: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_DROPHILITED) & @CRLF)
|
|---|
| 51 | Sleep(2000)
|
|---|
| 52 | _GUICtrlListView_SetItemFocused($ListView, 0, True)
|
|---|
| 53 | ConsoleWrite("SetItemFocused: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_FOCUSED) & @CRLF)
|
|---|
| 54 | Sleep(2000)
|
|---|
| 55 | _GUICtrlListView_SetItemFocused($ListView, 0, False)
|
|---|
| 56 | ConsoleWrite("SetItemFocused: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_FOCUSED) & @CRLF)
|
|---|
| 57 | Sleep(2000)
|
|---|
| 58 | ConsoleWrite("-End------------------------" & @CRLF)
|
|---|
| 59 | _SendMessage(GUICtrlGetHandle($ListView), $LVM_DELETEALLITEMS)
|
|---|
| 60 | Sleep(2000)
|
|---|
| 61 |
|
|---|
| 62 | ConsoleWrite("-Start--Fixed UDF's ----" & @CRLF)
|
|---|
| 63 | _GUICtrlListView_InsertItem($ListView, "TestText", 1)
|
|---|
| 64 | Sleep(2000)
|
|---|
| 65 | __GUICtrlListView_SetItemCut($ListView, 0, True)
|
|---|
| 66 | ConsoleWrite("SetItemCut: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_CUT) & @CRLF)
|
|---|
| 67 | Sleep(2000)
|
|---|
| 68 | __GUICtrlListView_SetItemCut($ListView, 0, False)
|
|---|
| 69 | ConsoleWrite("SetItemCut: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_CUT) & @CRLF)
|
|---|
| 70 | Sleep(2000)
|
|---|
| 71 | __GUICtrlListView_SetItemDropHilited($ListView, 0, True)
|
|---|
| 72 | ConsoleWrite("SetItemDropHilited: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_DROPHILITED) & @CRLF)
|
|---|
| 73 | Sleep(2000)
|
|---|
| 74 | __GUICtrlListView_SetItemDropHilited($ListView, 0, False)
|
|---|
| 75 | ConsoleWrite("SetItemDropHilited: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_DROPHILITED) & @CRLF)
|
|---|
| 76 | Sleep(2000)
|
|---|
| 77 | __GUICtrlListView_SetItemFocused($ListView, 0, True)
|
|---|
| 78 | ConsoleWrite("SetItemFocused: True, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_FOCUSED) & @CRLF)
|
|---|
| 79 | Sleep(2000)
|
|---|
| 80 | __GUICtrlListView_SetItemFocused($ListView, 0, False)
|
|---|
| 81 | ConsoleWrite("SetItemFocused: False, Result: "&_GUICtrlListView_GetItemState($ListView, 0, $LVIS_FOCUSED) & @CRLF)
|
|---|
| 82 | Sleep(2000)
|
|---|
| 83 | ConsoleWrite("-End------------------------" & @CRLF)
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | While 1
|
|---|
| 89 | Sleep(10)
|
|---|
| 90 | WEnd
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | ; #########################################################################
|
|---|
| 97 | ; #### Fixed UDF's using _GUICtrlListView_SetItemState in the right way ###
|
|---|
| 98 | ; #########################################################################
|
|---|
| 99 |
|
|---|
| 100 | Func __GUICtrlListView_SetItemCut($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 101 | Local $iState = 0
|
|---|
| 102 |
|
|---|
| 103 | If $fEnabled Then $iState = $LVIS_CUT
|
|---|
| 104 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $iState, $LVIS_CUT)
|
|---|
| 105 | EndFunc ;==>_GUICtrlListView_SetItemCut
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | Func __GUICtrlListView_SetItemFocused($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 109 | Local $iState = 0
|
|---|
| 110 |
|
|---|
| 111 | If $fEnabled Then $iState = $LVIS_FOCUSED
|
|---|
| 112 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $iState, $LVIS_FOCUSED)
|
|---|
| 113 | EndFunc ;==>_GUICtrlListView_SetItemFocused
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | Func __GUICtrlListView_SetItemDropHilited($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 117 | Local $iState = 0
|
|---|
| 118 |
|
|---|
| 119 | If $fEnabled Then $iState = $LVIS_DROPHILITED
|
|---|
| 120 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $iState, $LVIS_DROPHILITED)
|
|---|
| 121 | EndFunc ;==>_GUICtrlListView_SetItemDropHilited
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | ; ############################################################################
|
|---|
| 125 | ; #### Original UDF's using _GUICtrlListView_SetItemState in the wrong way ###
|
|---|
| 126 | ; ############################################################################
|
|---|
| 127 |
|
|---|
| 128 | Func _GUICtrlListView_SetItemCut($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 129 | Local $iStateMask = 0
|
|---|
| 130 |
|
|---|
| 131 | If $fEnabled Then $iStateMask = $LVIS_CUT
|
|---|
| 132 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $LVIS_CUT, $iStateMask)
|
|---|
| 133 | EndFunc ;==>_GUICtrlListView_SetItemCut
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | Func _GUICtrlListView_SetItemFocused($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 137 | Local $iStateMask = 0
|
|---|
| 138 |
|
|---|
| 139 | If $fEnabled Then $iStateMask = $LVIS_FOCUSED
|
|---|
| 140 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $LVIS_FOCUSED, $iStateMask)
|
|---|
| 141 | EndFunc ;==>_GUICtrlListView_SetItemFocused
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | Func _GUICtrlListView_SetItemDropHilited($hWnd, $iIndex, $fEnabled = True)
|
|---|
| 145 | Local $iStateMask = 0
|
|---|
| 146 |
|
|---|
| 147 | If $fEnabled Then $iStateMask = $LVIS_DROPHILITED
|
|---|
| 148 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, $LVIS_DROPHILITED, $iStateMask)
|
|---|
| 149 | EndFunc ;==>_GUICtrlListView_SetItemDropHilited
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | ; #################################################################################
|
|---|
| 154 | ; ### Other original UDF's using _GUICtrlListView_SetItemState in the right way ###
|
|---|
| 155 | ; #################################################################################
|
|---|
| 156 |
|
|---|
| 157 | Func _GUICtrlListView_SetItemOverlayImage($hWnd, $iIndex, $iImage)
|
|---|
| 158 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, _GUICtrlListView_IndexToOverlayImageMask($iImage), $LVIS_OVERLAYMASK)
|
|---|
| 159 | EndFunc ;==>_GUICtrlListView_SetItemOverlayImage
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | Func _GUICtrlListView_SetItemStateImage($hWnd, $iIndex, $iImage)
|
|---|
| 163 | Return _GUICtrlListView_SetItemState($hWnd, $iIndex, BitShift($iImage, -12), $LVIS_STATEIMAGEMASK)
|
|---|
| 164 | EndFunc ;==>_GUICtrlListView_SetItemStateImage
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 | ; #################################################################################
|
|---|
| 177 | ; ### Other original UDF's for making this example run ###
|
|---|
| 178 | ; #################################################################################
|
|---|
| 179 |
|
|---|
| 180 | Func _GUICtrlListView_SetItemState($hWnd, $iIndex, $iState, $iStateMask)
|
|---|
| 181 | Local $tItem
|
|---|
| 182 |
|
|---|
| 183 | $tItem = DllStructCreate($tagLVITEM)
|
|---|
| 184 | DllStructSetData($tItem, "Mask", $LVIF_STATE)
|
|---|
| 185 | DllStructSetData($tItem, "Item", $iIndex)
|
|---|
| 186 | DllStructSetData($tItem, "State", $iState)
|
|---|
| 187 | DllStructSetData($tItem, "StateMask", $iStateMask)
|
|---|
| 188 | Return _GUICtrlListView_SetItemEx($hWnd, $tItem) <> 0
|
|---|
| 189 | EndFunc ;==>_GUICtrlListView_SetItemState
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | Func _GUICtrlListView_SetItemEx($hWnd, ByRef $tItem)
|
|---|
| 193 | If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
|
|---|
| 194 | Local $iItem, $pItem, $iBuffer, $pBuffer, $pMemory, $tMemMap, $pText, $iResult
|
|---|
| 195 | Local $fUnicode = _GUICtrlListView_GetUnicodeFormat($hWnd)
|
|---|
| 196 |
|
|---|
| 197 | $pItem = DllStructGetPtr($tItem)
|
|---|
| 198 | If IsHWnd($hWnd) Then
|
|---|
| 199 | $iItem = DllStructGetSize($tItem)
|
|---|
| 200 | $iBuffer = DllStructGetData($tItem, "TextMax")
|
|---|
| 201 | If $fUnicode Then $iBuffer *= 2
|
|---|
| 202 | $pBuffer = DllStructGetData($tItem, "Text")
|
|---|
| 203 | $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
|
|---|
| 204 | $pText = $pMemory + $iItem
|
|---|
| 205 | DllStructSetData($tItem, "Text", $pText)
|
|---|
| 206 | _MemWrite($tMemMap, $pItem, $pMemory, $iItem)
|
|---|
| 207 | If $pBuffer <> 0 Then _MemWrite($tMemMap, $pBuffer, $pText, $iBuffer)
|
|---|
| 208 | If $fUnicode Then
|
|---|
| 209 | $iResult = _SendMessage($hWnd, $LVM_SETITEMW, 0, $pMemory, 0, "wparam", "ptr")
|
|---|
| 210 | Else
|
|---|
| 211 | $iResult = _SendMessage($hWnd, $LVM_SETITEMA, 0, $pMemory, 0, "wparam", "ptr")
|
|---|
| 212 | EndIf
|
|---|
| 213 | _MemFree($tMemMap)
|
|---|
| 214 | Else
|
|---|
| 215 | If $fUnicode Then
|
|---|
| 216 | $iResult = GUICtrlSendMsg($hWnd, $LVM_SETITEMW, 0, $pItem)
|
|---|
| 217 | Else
|
|---|
| 218 | $iResult = GUICtrlSendMsg($hWnd, $LVM_SETITEMA, 0, $pItem)
|
|---|
| 219 | EndIf
|
|---|
| 220 | EndIf
|
|---|
| 221 | Return $iResult <> 0
|
|---|
| 222 | EndFunc ;==>_GUICtrlListView_SetItemEx
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 | Func _GUICtrlListView_GetUnicodeFormat($hWnd)
|
|---|
| 226 | If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
|
|---|
| 227 | If IsHWnd($hWnd) Then
|
|---|
| 228 | Return _SendMessage($hWnd, $LVM_GETUNICODEFORMAT) <> 0
|
|---|
| 229 | Else
|
|---|
| 230 | Return GUICtrlSendMsg($hWnd, $LVM_GETUNICODEFORMAT, 0, 0) <> 0
|
|---|
| 231 | EndIf
|
|---|
| 232 | EndFunc ;==>_GUICtrlListView_GetUnicodeFormat
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | Func _GUICtrlListView_InsertItem($hWnd, $sText, $iIndex = -1, $iImage = -1, $iParam = 0)
|
|---|
| 236 | If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
|
|---|
| 237 | Local $iBuffer, $pBuffer, $tBuffer, $iItem, $pItem, $tItem, $pMemory, $tMemMap, $pText, $iMask, $iResult
|
|---|
| 238 | If $iIndex = -1 Then $iIndex = 999999999
|
|---|
| 239 | Local $fUnicode = _GUICtrlListView_GetUnicodeFormat($hWnd)
|
|---|
| 240 |
|
|---|
| 241 | $tItem = DllStructCreate($tagLVITEM)
|
|---|
| 242 | $pItem = DllStructGetPtr($tItem)
|
|---|
| 243 | DllStructSetData($tItem, "Param", $iParam)
|
|---|
| 244 | If $sText <> -1 Then
|
|---|
| 245 | $iBuffer = StringLen($sText) + 1
|
|---|
| 246 | If $fUnicode Then
|
|---|
| 247 | $iBuffer *= 2
|
|---|
| 248 | $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
|
|---|
| 249 | Else
|
|---|
| 250 | $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")
|
|---|
| 251 | EndIf
|
|---|
| 252 | $pBuffer = DllStructGetPtr($tBuffer)
|
|---|
| 253 | DllStructSetData($tBuffer, "Text", $sText)
|
|---|
| 254 | DllStructSetData($tItem, "Text", $pBuffer)
|
|---|
| 255 | DllStructSetData($tItem, "TextMax", $iBuffer)
|
|---|
| 256 | Else
|
|---|
| 257 | DllStructSetData($tItem, "Text", -1)
|
|---|
| 258 | EndIf
|
|---|
| 259 | $iMask = BitOR($LVIF_TEXT, $LVIF_PARAM)
|
|---|
| 260 | If $iImage >= 0 Then $iMask = BitOR($iMask, $LVIF_IMAGE)
|
|---|
| 261 | DllStructSetData($tItem, "Mask", $iMask)
|
|---|
| 262 | DllStructSetData($tItem, "Item", $iIndex)
|
|---|
| 263 | DllStructSetData($tItem, "Image", $iImage)
|
|---|
| 264 | If IsHWnd($hWnd) Then
|
|---|
| 265 | If _WinAPI_InProcess($hWnd, $_lv_ghLastWnd) Or ($sText = -1) Then
|
|---|
| 266 | If $fUnicode Then
|
|---|
| 267 | $iResult = _SendMessage($hWnd, $LVM_INSERTITEMW, 0, $pItem, 0, "wparam", "ptr")
|
|---|
| 268 | Else
|
|---|
| 269 | $iResult = _SendMessage($hWnd, $LVM_INSERTITEMA, 0, $pItem, 0, "wparam", "ptr")
|
|---|
| 270 | EndIf
|
|---|
| 271 | Else
|
|---|
| 272 | $iItem = DllStructGetSize($tItem)
|
|---|
| 273 | $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
|
|---|
| 274 | $pText = $pMemory + $iItem
|
|---|
| 275 | DllStructSetData($tItem, "Text", $pText)
|
|---|
| 276 | _MemWrite($tMemMap, $pItem, $pMemory, $iItem)
|
|---|
| 277 | _MemWrite($tMemMap, $pBuffer, $pText, $iBuffer)
|
|---|
| 278 | If $fUnicode Then
|
|---|
| 279 | $iResult = _SendMessage($hWnd, $LVM_INSERTITEMW, 0, $pMemory, 0, "wparam", "ptr")
|
|---|
| 280 | Else
|
|---|
| 281 | $iResult = _SendMessage($hWnd, $LVM_INSERTITEMA, 0, $pMemory, 0, "wparam", "ptr")
|
|---|
| 282 | EndIf
|
|---|
| 283 | _MemFree($tMemMap)
|
|---|
| 284 | EndIf
|
|---|
| 285 | Else
|
|---|
| 286 | If $fUnicode Then
|
|---|
| 287 | $iResult = GUICtrlSendMsg($hWnd, $LVM_INSERTITEMW, 0, $pItem)
|
|---|
| 288 | Else
|
|---|
| 289 | $iResult = GUICtrlSendMsg($hWnd, $LVM_INSERTITEMA, 0, $pItem)
|
|---|
| 290 | EndIf
|
|---|
| 291 | EndIf
|
|---|
| 292 | Return $iResult
|
|---|
| 293 | EndFunc ;==>_GUICtrlListView_InsertItem
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 | Func _GUICtrlListView_SetImageList($hWnd, $hHandle, $iType = 0)
|
|---|
| 298 | If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
|
|---|
| 299 | Local $aType[3] = [$LVSIL_NORMAL, $LVSIL_SMALL, $LVSIL_STATE]
|
|---|
| 300 |
|
|---|
| 301 | If IsHWnd($hWnd) Then
|
|---|
| 302 | Return _SendMessage($hWnd, $LVM_SETIMAGELIST, $aType[$iType], $hHandle, 0, "wparam", "hwnd", "hwnd")
|
|---|
| 303 | Else
|
|---|
| 304 | Return GUICtrlSendMsg($hWnd, $LVM_SETIMAGELIST, $aType[$iType], $hHandle)
|
|---|
| 305 | EndIf
|
|---|
| 306 | EndFunc ;==>_GUICtrlListView_SetImageList
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 | Func _GUICtrlListView_GetItemState($hWnd, $iIndex, $iMask)
|
|---|
| 310 | If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
|
|---|
| 311 | If IsHWnd($hWnd) Then
|
|---|
| 312 | Return _SendMessage($hWnd, $LVM_GETITEMSTATE, $iIndex, $iMask)
|
|---|
| 313 | Else
|
|---|
| 314 | Return GUICtrlSendMsg($hWnd, $LVM_GETITEMSTATE, $iIndex, $iMask)
|
|---|
| 315 | EndIf
|
|---|
| 316 | EndFunc ;==>_GUICtrlListView_GetItemState
|
|---|