Jump to content

Recommended Posts

Posted

I applied the style to the listbox and it works.

Now... How do you retrieve/use/find out all selected items?

I tried GUICtrlSendMsg, doesn't work.

Then I searched a bit and I saw that this-is-me often uses DllCall instead of GUICtrlSendMsg.

So I tried the same method using DllCall. The problem is, is that the specific function needs a pointer to an array.

I knew in advance this wouldn't work:

#include <GUIConstants.au3>
AutoItSetOption("TrayIconDebug", 1)

;Initialize variables
Global $style1
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 300
$GUIHeight = 250
$IniFile = StringTrimRight(@ScriptFullPath, 3) & "ini"

GUICreate("Synchro - Under Construction", $GUIWidth, $GUIHeight)

$LBS_MULTIPLESEL = 0x0008
$MissFileList = GUICtrlCreateList("", 10, 5, 280, 200, $LBS_MULTIPLESEL)
$Del_Btn = GUICtrlCreateButton("Delete", 20, 210, 70, 25)
$Copy_Btn = GUICtrlCreateButton("Copy", 115, 210, 70, 25)
$EXIT_Btn = GUICtrlCreateButton("Exit", 210, 210, 70, 25)

GUICtrlSetData($MissFileList, "Item 0|Item 1|Item 2|Item 3|Item 4|Item 5|Item 6|Item 7|Item 8|Item 9")
GUISetState(@SW_SHOW)

While 1
   Sleep(25)
   $msg = GUIGetMsg()
   Select
   
      Case $msg = $GUI_EVENT_CLOSE OR $msg = $EXIT_Btn
         GUIDelete()
         Exit

      Case $msg = $Del_Btn
         Dim $SelItems_buffer[10]
         $LB_GETSELITEMS = 0x0191
         $Items = DllCall("user32.dll", "int", "SendMessage", "hWnd", $MissFileList, "int", $LB_GETSELITEMS, "int", 10, "ptr", $SelItems_buffer)
         If UBound($Items) > 1 Then
            For $i = 0 To UBound($Items) - 1
               MsgBox(64, "Test", "$Items[" & $i & "] = " & $Items[$i])
            Next
         Else
            MsgBox(64, "Debug Test", "Return value: " & @CRLF & $Items[0])
         EndIf

   EndSelect
WEnd

I get strange results back. Random numbers in the $Items array.

I'll do some more tests but I don't think I can make this work.

What about you? Can you help me?

Posted

I applied the style to the listbox and it works.

Now... How do you retrieve/use/find out all selected items?

I tried GUICtrlSendMsg, doesn't work.

Then I searched a bit and I saw that this-is-me often uses DllCall instead of GUICtrlSendMsg.

So I tried the same method using DllCall. The problem is, is that the specific function needs a pointer to an array.

I knew in advance this wouldn't work:

Hi SlimShady nice script ,good to learn dll call on Autoit :D

Thx to Share it out! :idiot:

Posted

Why are you using DllCall for finding all selected ListBox-Items? Isn't the ControlListView()-function doing what you want it to do?

Have a look at the documentation and use ControlListView() with the command "GetSelected".

Posted (edited)

Hello? Did you read the title: Multiple selection Listbox

From Microsoft.com:

The Windows Forms ListView control displays a list of items with icons. You can use a list view to create a user interface like the right pane of Windows Explorer.

Edited by SlimShady
  • Administrators
Posted

yes... but the array it returns is defined completely differently than the array that you are used to in AutoIt. At this moment AutoIt is incompatible with this Sendmessage use.

Also, you may have noticed I retrieve the $hwnd for the control... I don't think GUICreateCtrl returns a hWnd...

Lar.

It returns a Control ID, so you could get the handle with something like

ControlGetHandle($myGuiHwnd, "", $controlID)

Also of interest is the control IDs that the CtrlCreate functions return _are_ the same as the ones you read in au3spy. How cosy.

Posted

I accidentally deleted my version of the GetSelected function.

I just remade it. I'll post it here just in case.

Func GetSelected($Ctrl_ID)
   Local $LB_GETSEL = 0x0187
   Local $LB_GETCOUNT = 0x018B
   Local $total_items, $list, $sel, $i
   
   $total_items = GUICtrlSendMsg($Ctrl_ID, $LB_GETCOUNT, 0, 0)
   If $total_items < 1 Then Return StringSplit($list, ",")
   
   For $i = 0 To $total_items - 1
      $sel = GUICtrlSendMsg($Ctrl_ID, $LB_GETSEL, $i, 0)
      If $sel Then $list = $list & $i & ","
   Next
   Return StringSplit(StringTrimRight($list, 1), ",")
EndFunc
Posted

*I don't feel like opening amnother topic...*

I have a script that uses my ListItemRename function with a multi-select List Box.

It doesn't work.

So I made a "small" test script and it still doesn't work.

Then I changed the list box (and other things) to single-select. And it worked.

Could you please check it out.

It could be a bug. I can't remember if it worked yesterday or the day before.

Test script is attached.

Thanks in advance.

Posted

Really strange:

I used DllCall+SendMessage with the same values and it worked.

I'll attach the script. The ListItemRename UDF contains both methods so you can take a look.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...