MrCreatoR Posted October 5, 2008 Share Posted October 5, 2008 (edited) Hi,This script was inspired by the example of PaulIA here.I made it easy to set dragable items for specific ListBox control, you can unset them to Here is an example:#include <GuiConstantsEx.au3> #include <DragList_UDF.au3> $hGUI = GUICreate("_DragList_... Demo", 400, 200) $nList1 = GUICtrlCreateList("", 20, 10, 160, 140, $WS_BORDER+$WS_VSCROLL) GUICtrlSetData($nList1, "Hi,|How|Are|You?") $nList2 = GUICtrlCreateList("", 220, 10, 160, 140, $WS_BORDER+$WS_VSCROLL) GUICtrlSetData($nList2, "AutoIt|Is|The|Best!") $SetList1_CheckBox = GUICtrlCreateCheckBox("Set List 1", 60, 160, 70, 20) $SetList2_CheckBox = GUICtrlCreateCheckBox("Set List 2", 260, 160, 70, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $SetList1_CheckBox If GUICtrlRead($SetList1_CheckBox) = $GUI_CHECKED Then _DragList_SetList($nList1, $hGUI) Else _DragList_SetList($nList1) EndIf Case $SetList2_CheckBox If GUICtrlRead($SetList2_CheckBox) = $GUI_CHECKED Then _DragList_SetList($nList2, $hGUI) Else _DragList_SetList($nList2) EndIf EndSwitch WendJust set the checkboxes, and try to drag the items .This example + DragList_UDF.au3 (functions and the main handler) attached as zip file:_DragList_UDF.zipEnjoy! Edited October 5, 2008 by MrCreatoR xeroTechnologiesLLC 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Andreik Posted October 5, 2008 Share Posted October 5, 2008 Yeah, very good example. I like that arrow . Good work MrCreatoR. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ludocus Posted October 5, 2008 Share Posted October 5, 2008 Good job!!.. works fine. Link to comment Share on other sites More sharing options...
ken82m Posted January 12, 2009 Share Posted January 12, 2009 Exactly what I was looking for. As always thank you "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
ken82m Posted January 12, 2009 Share Posted January 12, 2009 is it possible to select lets say a group of 5 items and move them all at once? "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted April 11, 2012 Share Posted April 11, 2012 Masterful - very well done. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 11, 2012 Share Posted April 11, 2012 You shouldn't be commenting on every ancient topic that helps you. Necroposting is a big no-no. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Spenhouet Posted June 5, 2012 Share Posted June 5, 2012 Does this work with ListView? When i use it...my list is frozen... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2012 Moderators Share Posted June 5, 2012 Spenhouet,No, this UDF deals with ListBoxes - ListViews are a very different beast. If you want to drag items within a ListView, take a look at the GUIListViewEx UDF in my sig. M23 Spenhouet 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Leo1906 Posted June 29, 2016 Share Posted June 29, 2016 This doens't work if you compile the script for x64 Systems .. Does anyone knows a solution? Link to comment Share on other sites More sharing options...
LarsJ Posted June 29, 2016 Share Posted June 29, 2016 Replace the old version of _DragList_GetItemFromPoint with this new version: #cs Func _DragList_GetItemFromPoint($hList, $stPoint, $iAutoscroll = 0) ;The return value contains the index of the nearest item in the low-order word. ;The high-order word is zero if the specified point is in the client area of the list box, ;or one if it is outside the client area.>>>Note. this call to sendmessage always results in the same number<<< Local $iX = DllStructGetData($stPoint, 1) Local $iY = DllStructGetData($stPoint, 2) Local $aRet = DllCall("comctl32.dll", "int", "LBItemFromPt", "hwnd", $hList, "int", $iX, "int", $iY, "int", $iAutoscroll) Return $aRet[0] EndFunc #ce Func _DragList_GetItemFromPoint($hList, $stPoint, $iAutoscroll = 0) ;The return value contains the index of the nearest item in the low-order word. ;The high-order word is zero if the specified point is in the client area of the list box, ;or one if it is outside the client area.>>>Note. this call to sendmessage always results in the same number<<< Local $tPOINT64 = DllStructCreate( "int64", DllStructGetPtr( $stPoint ) ) Local $aRet = DllCall("comctl32.dll", "int", "LBItemFromPt", "hwnd", $hList, "int64", DllStructGetData( $tPOINT64, 1 ), "int", $iAutoscroll) Return $aRet[0] EndFunc The new version works on both 32 and 64 bit. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Leo1906 Posted June 29, 2016 Share Posted June 29, 2016 2 hours ago, LarsJ said: Replace the old version of _DragList_GetItemFromPoint with this new version: #cs Func _DragList_GetItemFromPoint($hList, $stPoint, $iAutoscroll = 0) ;The return value contains the index of the nearest item in the low-order word. ;The high-order word is zero if the specified point is in the client area of the list box, ;or one if it is outside the client area.>>>Note. this call to sendmessage always results in the same number<<< Local $iX = DllStructGetData($stPoint, 1) Local $iY = DllStructGetData($stPoint, 2) Local $aRet = DllCall("comctl32.dll", "int", "LBItemFromPt", "hwnd", $hList, "int", $iX, "int", $iY, "int", $iAutoscroll) Return $aRet[0] EndFunc #ce Func _DragList_GetItemFromPoint($hList, $stPoint, $iAutoscroll = 0) ;The return value contains the index of the nearest item in the low-order word. ;The high-order word is zero if the specified point is in the client area of the list box, ;or one if it is outside the client area.>>>Note. this call to sendmessage always results in the same number<<< Local $tPOINT64 = DllStructCreate( "int64", DllStructGetPtr( $stPoint ) ) Local $aRet = DllCall("comctl32.dll", "int", "LBItemFromPt", "hwnd", $hList, "int64", DllStructGetData( $tPOINT64, 1 ), "int", $iAutoscroll) Return $aRet[0] EndFunc The new version works on both 32 and 64 bit. Wow! Thanks for that But now I have a different kind of problem. When using this UDF it seems like the style $LBS_EXTENDEDSEL has to be turned off in order to see what item is selected. (blue highlighted) But I need to create the ListBox with this style: $List = GUICtrlCreateList("", 40, 104, 193, 227, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_EXTENDEDSEL)) to use some functions like "_GUICtrlListBox_GetSelItems($List)" Any suggestions on this one? Link to comment Share on other sites More sharing options...
x_bennY Posted January 19, 2018 Share Posted January 19, 2018 why i cant move the item to the last position? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 19, 2018 Moderators Share Posted January 19, 2018 @x_bennY do you honestly believe this is enough information for someone to help you?? How about providing your code, rather than asking us to guess? Earthshine 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
x_bennY Posted January 20, 2018 Share Posted January 20, 2018 @JLogan3o13 sorry... i'm using the script posted here, and it works very well, but when i try do move some of the items in the listbox to the last position it doesn't move! Link to comment Share on other sites More sharing options...
LarsJ Posted January 20, 2018 Share Posted January 20, 2018 This is not an error. The code is designed to work that way. When you move items in a listbox with the mouse, you can either drop items above or below the target item. Here it's chosen to drop items above the target item with the consequence that you cannot drop items below last item (only above last item). You could also have chosen to drop items below the target item. Then there would have been a similar problem with the first item. Solution. Drop your item just above the last item. Move the last item one item up. x_bennY 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
x_bennY Posted January 22, 2018 Share Posted January 22, 2018 I found a solution searching here on autoit forum. expandcollapse popup#include <Constants.au3> #include <GUIListBox.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $gnDRAGLISTMSGSTRING = _WinAPI_RegisterWindowMessage("commctrl_DragListMsg") Global $DL_BEGINDRAG = $WM_USER + 133 Global $DL_DRAGGING = $WM_USER + 134 Global $DL_DROPPED = $WM_USER + 135 Global $DL_CANCELDRAG = $WM_USER + 136 Global Enum $DL_STOPCURSOR = 1, $DL_COPYCURSOR, $DL_MOVECURSOR Global $gtDRAGLISTINFO = "long uNotification;long hWnd;long x;long y" Global $gfItemAdded = False Global $hMain = GUICreate("DragList", 200, 400) Global $cListbox = GUICtrlCreateList("", 16, 16, 168, 368, $WS_BORDER + $WS_VSCROLL) GUICtrlSetFont($cListbox, 10, Default, Default, "Tahoma") Global $hListbox = GUICtrlGetHandle($cListbox) GUICtrlSetData($cListbox, "Apples|Oranges|Bananas|Pears|Grapefruits|Limes|Lemons|Strawberries|Plums|Melons|Grapes|") GUISetState() _ComCtl32_MakeDragList($hListbox) Global $wProcNew = DllCallbackRegister("_MyWndProc", "int", "hwnd;int;wparam;lparam") Global $wProcOld = _WinAPI_SetWindowLong($hMain, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) While GUIGetMsg() <> -3 Sleep(10) Wend _WinAPI_SetWindowLong($hMain, $GWL_WNDPROC, DllCallbackGetPtr($wProcOld)) Exit Func _MyWndProc($hWnd, $nMsg, $wParam, $lParam) Local $aRet, $nOldIndex, $sItemText If $nMsg = $gnDRAGLISTMSGSTRING Then Local $tDRAGLISTINFO = DllStructCreate($gtDRAGLISTINFO, $lParam) Local $uNotification = DllStructGetData($tDRAGLISTINFO, "uNotification") Local $x = DllStructGetData($tDRAGLISTINFO, "x"), $y = DllStructGetData($tDRAGLISTINFO, "y") Local $nItem = _ComCtl32_LBItemFromPt($hListbox, $x, $y) Switch $uNotification Case $DL_BEGINDRAG If $nItem < (_GUICtrlListBox_GetCount($hListbox) - 1) Then _GUICtrlListBox_AddString($hListbox, "") $gfItemAdded = True EndIf Return 1 Case $DL_DRAGGING _ComCtl32_DrawInsert($hMain, $hListbox, $nItem) If $nItem = _GUICtrlListBox_GetCurSel($hListbox) Then Return $DL_STOPCURSOR Return $DL_MOVECURSOR Case $DL_DROPPED If $nItem > -1 Then $nOldIndex = _GUICtrlListBox_GetCurSel($hListbox) If $nItem <> $nOldIndex Then $sItemText = _GUICtrlListBox_GetText($hListbox, $nOldIndex) If $nItem < $nOldIndex Then $nOldIndex += 1 _GUICtrlListBox_InsertString($hListbox, $sItemText, $nItem) _GUICtrlListBox_DeleteString($hListbox, $nOldIndex) If $nItem > $nOldIndex Then $nItem -= 1 _GUICtrlListBox_SetCurSel($hListbox, $nItem) EndIf EndIf If $gfItemAdded Then _GUICtrlListBox_DeleteString($hListbox, _GUICtrlListBox_GetCount($hListbox) - 1) $gfItemAdded = False EndIF _ComCtl32_DrawInsert($hMain, $hListbox, -1) Return 0 Case $DL_CANCELDRAG If $gfItemAdded Then _GUICtrlListBox_DeleteString($hListbox, _GUICtrlListBox_GetCount($hListbox) - 1) $gfItemAdded = False EndIF _ComCtl32_DrawInsert($hMain, $hListbox, -1) Return 0 EndSwitch EndIf Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $nMsg, $wParam, $lParam) EndFunc Func _ComCtl32_MakeDragList($hWnd) Local $aRet = DllCall("comctl32.dll", "int", "MakeDragList", "hwnd", $hWnd) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func _ComCtl32_LBItemFromPt($hWnd, $x, $y) Local $aRet = DllCall("comctl32.dll", "long", "LBItemFromPt", "hwnd", $hWnd, "long", $x, "long", $y, "long", 1) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func _ComCtl32_DrawInsert($hWndParent, $hWnd, $nItem) DllCall("comctl32.dll", "none", "DrawInsert", "hwnd", $hWndParent, "hwnd", $hWnd, "long", $nItem) If @error Then Return SetError(@error, @extended, 0) Return EndFunc Link to comment Share on other sites More sharing options...
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