Modify ↓
#3233 closed Bug (Fixed)
_GUICtrlListBox_GetSelCount returns 0 also if $hwnd isn't a handle
Reported by: | autoBert | Owned by: | guinness |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | 3.3.14.0 | Severity: | None |
Keywords: | Cc: |
Description
_GUICtrlListBox_GetSelCount returns 0 if no items selected. Helpfile say: Failure: -1 if no items are selected.
also if $hwnd isn't a handle 0 is returned.
#include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $idListBox ; Create GUI GUICreate("List Box Get Sel Count", 400, 296) $idListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) GUISetState(@SW_SHOW) ; Add strings _GUICtrlListBox_BeginUpdate($idListBox) For $iI = 1 To 9 _GUICtrlListBox_AddString($idListBox, StringFormat("%03d : Random string", Random(1, 100, 1))) Next _GUICtrlListBox_EndUpdate($idListBox) ;Should show -1 but show 0 ;Helpfile: Failure: -1 if no items are selected. MsgBox($MB_SYSTEMMODAL, "Information (no Item selected)", "Items Selected: " & _GUICtrlListBox_GetSelCount($idListBox)) ; Select a few items _GUICtrlListBox_SetSel($idListBox, 3) _GUICtrlListBox_SetSel($idListBox, 4) _GUICtrlListBox_SetSel($idListBox, 5) ;Should show -1 but show 0 ;Helpfile: Failure: -1 if no items are selected. ;note the func is called with no hwnd so maybe in future use @error and @extended MsgBox($MB_SYSTEMMODAL, "Information (no HWND)", "Items Selected: " & _GUICtrlListBox_GetSelCount('1234')) ; Show the item selection count MsgBox($MB_SYSTEMMODAL, "Information (that's correct)", "Items Selected: " & _GUICtrlListBox_GetSelCount($idListBox)) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example
Attachments (0)
Change History (6)
comment:1 Changed 9 years ago by Melba23
comment:2 Changed 9 years ago by mLipok
Small proposal:
Func _GUICtrlListBox_GetSelCount_Mod($hWnd) If IsHWnd($hWnd) Then Return _SendMessage($hWnd, $LB_GETSELCOUNT) ElseIf IsHwnd(GUICtrlGetHandle($hWnd)) Then Return GUICtrlSendMsg($hWnd, $LB_GETSELCOUNT, 0, 0) EndIf Return -1 ; Invalid controlID EndFunc ;==>_GUICtrlListBox_GetSelCount_Mod
comment:3 Changed 9 years ago by Melba23
mLipok,
Looks fine to me.
M23
comment:4 Changed 8 years ago by guinness
- Milestone set to 3.3.15.1
- Owner set to guinness
- Resolution set to Fixed
- Status changed from new to closed
Fixed by revision [11708] in version: 3.3.15.1
comment:5 Changed 8 years ago by guinness
Fixed by revision [11709] in version: 3.3.15.1
comment:6 Changed 8 years ago by guinness
- Milestone 3.3.15.1 deleted
I commited with a slight variation of mLipok's code suggestion
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Note: See
TracTickets for help on using
tickets.
How about if we change the Help file to read:
and then use this modified function:
M23