Davidyese Posted 10 hours ago Posted 10 hours ago (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 : expandcollapse popup#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 10 hours ago by Davidyese
Nine Posted 9 hours ago Posted 9 hours ago One simple way : Case $GUI_EVENT_DROPPED _ArrayConcatenate($aList, $gaDropFiles) $aList = _ArrayUnique($aList) _ArrayDelete($aList, 0) GUICtrlSetData($hList, "") GUICtrlSetData($hList, _ArrayToString($aList)) Davidyese 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
argumentum Posted 9 hours ago Posted 9 hours ago (edited) Made a file named "New Ľ Text ↔ Document.txt" and _GUICtrlListBox_GetText() is different from $gaDropFiles[$i]. No clue of why. My bad. It is the same. Edited 9 hours ago by argumentum oops Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted 9 hours ago Posted 9 hours ago expandcollapse popup#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. Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Davidyese Posted 8 hours ago Author Posted 8 hours ago 5 minutes ago, argumentum said: expandcollapse popup#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 argumentum 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now