Jump to content

Recommended Posts

Posted (edited)

I need to add more items to listbox already added before via drag & drop without repetition

Beside add a way to remove duplicates of items

Any help to adjust the code

Thanks in advance

my code :

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

;Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

### Koda GUI section start ###
$Main_Gui = GUICreate("Drag&Drop into CreateList", 600, 300, -1,-1,-1,BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))

$Child_Gui = GUICreate("Child Gui", 480, 460, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $Main_Gui)
$button = GUICtrlCreateButton("", 20, 40, 120, 25)
GUICtrlSetState(-1, $GUI_HIDE)
GUISwitch($Main_Gui)
GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)
$tab = GUICtrlCreateTab(10, 10, 490, 490)
GUICtrlSetState(-1, $GUI_HIDE)

$hList = GUICtrlCreateList("", 10, 5, 575, 100, BitOR($LBS_EXTENDEDSEL, $WS_BORDER, $WS_VSCROLL, $LBS_STANDARD, $LBS_SORT))
GUICtrlSetState(-1, BitOR($GUI_FOCUS, $GUI_DROPACCEPTED))

GUISetState(@SW_SHOW)
### Koda GUI section end   ###

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_UNICODE_FUNC")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            For $i = 0 To UBound($gaDropFiles) - 1
               $str &= "|" & $gaDropFiles[$i]
            Next
            GUICtrlSetData($hList, StringTrimLeft($str, 1))

    EndSwitch
WEnd

Func WM_DROPFILES_UNICODE_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("wchar[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "int", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_UNICODE_FUNC

 

Edited by Davidyese
Posted

One simple way :

Case $GUI_EVENT_DROPPED
        _ArrayConcatenate($aList, $gaDropFiles)
        $aList = _ArrayUnique($aList)
        _ArrayDelete($aList, 0)
        GUICtrlSetData($hList, "")
        GUICtrlSetData($hList, _ArrayToString($aList))

 

Posted
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

;Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

### Koda GUI section start ###
$Main_Gui = GUICreate("Drag&Drop into CreateList", 600, 300, -1,-1,-1,BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))

$Child_Gui = GUICreate("Child Gui", 480, 460, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $Main_Gui)
$button = GUICtrlCreateButton("", 20, 40, 120, 25)
GUICtrlSetState(-1, $GUI_HIDE)
GUISwitch($Main_Gui)
GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)
$tab = GUICtrlCreateTab(10, 10, 490, 490)
GUICtrlSetState(-1, $GUI_HIDE)

$idList = GUICtrlCreateList("", 10, 5, 575, 100, BitOR($LBS_EXTENDEDSEL, $WS_BORDER, $WS_VSCROLL, $LBS_STANDARD, $LBS_SORT))
$hList = GUICtrlGetHandle($idList)
GUICtrlSetState(-1, BitOR($GUI_FOCUS, $GUI_DROPACCEPTED))

GUISetState(@SW_SHOW)
### Koda GUI section end   ###

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_UNICODE_FUNC")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED

            For $i = 0 To UBound($gaDropFiles) - 1
                ConsoleWrite($i & '  >' & $gaDropFiles[$i] & '<  ' & StringLen($gaDropFiles[$i]) & @CRLF)
                $iFound = 0
                For $n = 0 To _GUICtrlListBox_GetCount($hList) - 1
                    If _GUICtrlListBox_GetText($hList, $n) = $gaDropFiles[$i] Then $iFound = 1
                Next
                If $iFound Then ContinueLoop
                GUICtrlSetData($idList, $gaDropFiles[$i], 1) ; <=== my change
            Next
    EndSwitch
WEnd

Func WM_DROPFILES_UNICODE_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("wchar[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "int", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_UNICODE_FUNC

Try this. See if this does it.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
5 minutes ago, argumentum said:
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

;Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

### Koda GUI section start ###
$Main_Gui = GUICreate("Drag&Drop into CreateList", 600, 300, -1,-1,-1,BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))

$Child_Gui = GUICreate("Child Gui", 480, 460, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $Main_Gui)
$button = GUICtrlCreateButton("", 20, 40, 120, 25)
GUICtrlSetState(-1, $GUI_HIDE)
GUISwitch($Main_Gui)
GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)
$tab = GUICtrlCreateTab(10, 10, 490, 490)
GUICtrlSetState(-1, $GUI_HIDE)

$idList = GUICtrlCreateList("", 10, 5, 575, 100, BitOR($LBS_EXTENDEDSEL, $WS_BORDER, $WS_VSCROLL, $LBS_STANDARD, $LBS_SORT))
$hList = GUICtrlGetHandle($idList)
GUICtrlSetState(-1, BitOR($GUI_FOCUS, $GUI_DROPACCEPTED))

GUISetState(@SW_SHOW)
### Koda GUI section end   ###

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_UNICODE_FUNC")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED

            For $i = 0 To UBound($gaDropFiles) - 1
                ConsoleWrite($i & '  >' & $gaDropFiles[$i] & '<  ' & StringLen($gaDropFiles[$i]) & @CRLF)
                $iFound = 0
                For $n = 0 To _GUICtrlListBox_GetCount($hList) - 1
                    If _GUICtrlListBox_GetText($hList, $n) = $gaDropFiles[$i] Then $iFound = 1
                Next
                If $iFound Then ContinueLoop
                GUICtrlSetData($idList, $gaDropFiles[$i], 1) ; <=== my change
            Next
    EndSwitch
WEnd

Func WM_DROPFILES_UNICODE_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("wchar[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "int", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_UNICODE_FUNC

Try this. See if this does it.

You did the job, it's working now as i need

Thanks my dear

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...