Sign in to follow this  
Followers 0
MrCreatoR

Set Drag & Drop items for your ListBox'es

12 posts in this topic

#1 ·  Posted (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 :idea:

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
Wend

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

Enjoy! :P

Edited by MrCreatoR
1 person likes this

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



Yeah, very good example. I like that arrow :P . Good work MrCreatoR.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Good job!!..

works fine.

Share this post


Link to post
Share on other sites

Exactly what I was looking for. As always thank you :)


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

is it possible to select lets say a group of 5 items and move them all at once?


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

Masterful - very well done.

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

Does this work with ListView? When i use it...my list is frozen...

Share this post


Link to post
Share on other sites

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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

This doens't work if you compile the script for x64 Systems ..
Does anyone knows a solution?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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? :)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0