本帖最后由 afan 于 2019-8-20 19:10 编辑
ListBox 比 ListView 简单很多,所以没有那么多丰富的消息、处理函数#include <GuiListBox.au3>
GUICreate('')
Local $test1 = GUICtrlCreateList("", 10, 10, 150, 350, BitOR(0x00000003, 0x00000800))
GUICtrlSetData($test1, '11111' & @TAB & '22222|33333|44444|55555' & @TAB & '66666')
GUISetState()
Local $ix_now = -1
While 1
$Msg = GUIGetMsg()
Select
Case $Msg = -3
Exit
Case $Msg = $test1
$iIndex = __GUICtrlListBox_GetClickItem($test1) ;获取列表当前点击的项目(返回值<0即为非项目)
If $iIndex < 0 Then
ToolTip('无项目')
ContinueLoop
EndIf
If GUICtrlSendMsg($test1, 0x0187, $iIndex, 0) Then ;$LB_GETSEL = 0x0187
If $ix_now <> $iIndex Then
$ix_now = $iIndex
ToolTip('选中: ' & $ix_now)
Else
GUICtrlSendMsg($test1, 0x0185, False, $iIndex) ;$LB_SETSEL = 0x0185
$ix_now = -1
ToolTip('取消选中')
EndIf
EndIf
EndSelect
WEnd
Func __GUICtrlListBox_GetClickItem($iCTRL) ;获取列表当前点击的项目(返回值<0即为非项目)
;$iCTRL - 控件ID,此函数未作出句柄情况下的处理
Local $iIndex = _GUICtrlListBox_GetCaretIndex($iCTRL)
Local $ap = _GUICtrlListBox_GetItemRect($iCTRL, $iIndex)
Local $aMs = GUIGetCursorInfo()
If @error Then Return SetError(1)
If $aMs[4] <> $iCTRL Then Return SetError(1, 0, -2)
Local $aCPos = ControlGetPos('', '', $iCTRL)
If @error Then Return SetError(2, 0, -2)
If $aMs[1] - $aCPos[1] > $ap[3] Then Return SetError(3, 0, -1)
Return $iIndex
EndFunc ;==>__GUICtrlListBox_GetClickItem
|