Jump to content

Drag & Drop LV item, and draw line while dragging


MrCreatoR
 Share

Recommended Posts

Hi,

I am currently trying to make a dragable listview item(s), and i want to display a line that will indicate where it should be dropped.

I managed to make the drag & drop operation (modified from some old script that i found here on the forum), but i have problem with the line drawing, it's drawn, but not properly, i need to refresh the items before draw any new line, but here is the problem, sometimes there is two (or more) lines drawn :mellow:

Eventually i would like to modify it in the way that allows to drag & drop more than one item, but for now i only need to solve the line drawing issue.

Here is what i got so far:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $bDragging = False
Global $iLast_Index = -1
Global $a_Index[2] ; From and to

$Main_GUI = GUICreate("Drag & Drop LV Item", 225, 400, -1, -1, BitOR($WS_THICKFRAME, $WS_SIZEBOX))

$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, $LVS_SINGLESEL)
$h_ListView = GUICtrlGetHandle($ListView)

_GUICtrlListView_SetColumnWidth($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth($ListView, 1, 100)

GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES)

GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_SUBITEMIMAGES)

$h_ImageList = _GUIImageList_Create(20, 20, 5, 0, 4, $LVSIL_SMALL)

For $i = 0 To 10
    _GUIImageList_AddIcon($h_ImageList, @SystemDir & "\shell32.dll", $i)
Next

_GUICtrlListView_SetImageList($h_ListView, $h_ImageList, $LVSIL_SMALL)

For $i = 0 To 9
    GUICtrlCreateListViewItem("Name " & $i & "|Category " & $i, $ListView)
    _GUICtrlListView_SetItemImage($h_ListView, $i, $i, 0) ; listview handle, index, subitem, image index
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_EVENTS")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP_EVENTS")
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE_EVENTS")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUIImageList_Destroy($h_ImageList)
            Exit
    EndSwitch
WEnd

Func WM_LBUTTONUP_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    $bDragging = False
    
    DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $h_ListView, "ptr", 0, "int", 0, "int", 5)
    $iLast_Index = -1
    
    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)
    
    Local $iX = BitAND($lParam, 0xFFFF) - $aLV_Pos[0]
    Local $iY = BitShift($lParam, 16) - $aLV_Pos[1]
    
    Local $struct_LVHITTESTINFO = DllStructCreate("int;int;uint;int;int;int")
    
    DllStructSetData($struct_LVHITTESTINFO, 1, $iX)
    DllStructSetData($struct_LVHITTESTINFO, 2, $iY)
    
    $a_Index[1] = GUICtrlSendMsg($ListView, $LVM_HITTEST, 0, DllStructGetPtr($struct_LVHITTESTINFO))
    Local $iFlags = DllStructGetData($struct_LVHITTESTINFO, 2)
    
    ;// Out of the ListView?
    If $a_Index[1] == -1 Then Return $GUI_RUNDEFMSG
    
    ;// Not in an item?
    If BitAND($iFlags, $LVHT_ONITEMLABEL) == 0 And BitAND($iFlags, $LVHT_ONITEMSTATEICON) == 0 Then Return $GUI_RUNDEFMSG
    
    If $a_Index[0] <> $a_Index[1] Then
        ;ConsoleWrite($a_Index[0] & " ==> " & $a_Index[1] & @CRLF)
        _GUICtrlListView_CopyItem($h_ListView, $h_ListView, $a_Index[0], $a_Index[1], 1)
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_MOUSEMOVE_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    If Not $bDragging Then Return $GUI_RUNDEFMSG
    
    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)
    
    Local $iX = BitAND($lParam, 0xFFFF) - $aLV_Pos[0]
    Local $iY = BitShift($lParam, 16) - $aLV_Pos[1]
    
    Local $struct_LVHITTESTINFO = DllStructCreate("int;int;uint;int;int;int")
    
    DllStructSetData($struct_LVHITTESTINFO, 1, $iX)
    DllStructSetData($struct_LVHITTESTINFO, 2, $iY)
    
    Local $iItem = GUICtrlSendMsg($ListView, $LVM_HITTEST, 0, DllStructGetPtr($struct_LVHITTESTINFO))
    If $iItem = -1 Then Return $GUI_RUNDEFMSG
    
    If $iLast_Index = $iItem Then Return $GUI_RUNDEFMSG
    
    If $iLast_Index > $iItem Then ;Move up
        _GUICtrlListView_RedrawItems($ListView, $iItem, $iLast_Index)
    Else
        _GUICtrlListView_RedrawItems($ListView, $iLast_Index, $iItem-1)
    EndIf
    
    $iLast_Index = $iItem
    
    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)
    Local $iY = _GUICtrlListView_GetItemPositionY($ListView, $iItem)
    
    If $iY <= 0 Then Return $GUI_RUNDEFMSG
    
    _DrawLine($aLV_Pos[0], $iY, $aLV_Pos[2], 3, 0xFF0000, $h_ListView)
EndFunc

Func WM_NOTIFY_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $iEvent, $hwndFrom, $iCode, $iItem
    
    $tagNMHDR = DllStructCreate("int;int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code, Item)
    If @error Then Return $GUI_RUNDEFMSG
    
    $iCode = DllStructGetData($tagNMHDR, 3)
    $iItem = DllStructGetData($tagNMHDR, 4)
    
    Switch $wParam
        Case $ListView
            Switch $iCode
                Case $LVN_BEGINDRAG
                    $a_Index[0] = $iItem
                    $bDragging = True
                    
                    _GUICtrlListView_SetItemSelected($ListView, $iItem, False)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _GUICtrlListView_CopyItem($hWnd_Source, $hWnd_Destination, $iSrcIndex, $iDstIndex, $fDelFlag = False)
    Local $iInsert_Index
    Local $tItem = DllStructCreate($tagLVITEM)
    
    Local $iCols = _GUICtrlListView_GetColumnCount($hWnd_Source)
    Local $iItems = _GUICtrlListView_GetItemCount($hWnd_Source)
    Local $iDest_Items = _GUICtrlListView_GetItemCount($hWnd_Destination)
    
    _GUICtrlListView_BeginUpdate($hWnd_Source)
    If $hWnd_Destination <> $hWnd_Source Then _GUICtrlListView_BeginUpdate($hWnd_Destination)
    
    DllStructSetData($tItem, "Mask", BitOR($LVIF_GROUPID, $LVIF_IMAGE, $LVIF_INDENT, $LVIF_PARAM, $LVIF_STATE))
    DllStructSetData($tItem, "Item", $iSrcIndex)
    DllStructSetData($tItem, "SubItem", 0)
    DllStructSetData($tItem, "StateMask", -1)
    
    _GUICtrlListView_GetItemEx($hWnd_Source, $tItem)
    
    If $iDstIndex > $iSrcIndex Then
        $iDstIndex += 1
    ElseIf $iSrcIndex > $iDstIndex Then
        $iSrcIndex += 1
    EndIf
    
    $iInsert_Index = _GUICtrlListView_InsertItem($hWnd_Destination,  _
        _GUICtrlListView_GetItemText($hWnd_Source, $iSrcIndex, 0), $iDstIndex, DllStructGetData($tItem, "Image"))
    
    If BitAND(_GUICtrlListView_GetExtendedListViewStyle($hWnd_Source), $LVS_EX_CHECKBOXES) == $LVS_EX_CHECKBOXES Then
        If _GUICtrlListView_GetItemChecked($hWnd_Source, $iSrcIndex) Then _
            _GUICtrlListView_SetItemChecked($hWnd_Destination, $iInsert_Index)
    EndIf
    
    For $i = 0 To $iCols - 1
        DllStructSetData($tItem, "Item", $iInsert_Index)
        DllStructSetData($tItem, "SubItem", $i)
        
        _GUICtrlListView_GetItemEx($hWnd_Source, $tItem)
        
        _GUICtrlListView_AddSubItem($hWnd_Destination, $iInsert_Index, _
            _GUICtrlListView_GetItemText($hWnd_Source, $iSrcIndex, $i), $i, DllStructGetData($tItem, "Image"))
    Next
    
    If $fDelFlag Then _GUICtrlListView_DeleteItem($hWnd_Source, $iSrcIndex)
    
    If $iDstIndex > $iSrcIndex Then $iDstIndex -= 1
    _GUICtrlListView_SetItemSelected($hWnd_Source, $iDstIndex)
    
    _GUICtrlListView_EndUpdate($hWnd_Source)
    If $hWnd_Destination <> $hWnd_Source Then _GUICtrlListView_EndUpdate($hWnd_Destination)
    
    _GUICtrlListView_RedrawItems($hWnd_Destination, $iSrcIndex, $iDstIndex)
    ;DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $hWnd_Destination, "ptr", 0, "int", 0, "int", 5)
EndFunc

Func _DrawLine($iLeft, $iTop, $iWidth, $iHeight, $sColor, $hWnd=0)
    $sColor = Hex("0x" & BitAND(BitShift(String(Binary($sColor)), 8), 0xFFFFFF)) ;RGB2BGR
    
    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iHeight, "int", $sColor)
    
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
    DllCall("GDI32.dll", "int", "DeleteObject", "int", $aPen[0])
EndFunc

 

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

Link to comment
Share on other sites

Bump :mellow:

 

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

Link to comment
Share on other sites

Bump :mellow:

This seems to work, though you can't move an item to the end but I haven't worried about that.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $bDragging = False
Global $iLast_Index = -1
Global $a_Index[2]; From and to
Global $iLastLinetop, $iLastLineLeft
Global $drawing = False; to ensure mousemove doesn't cause more than one line to be drawn

$Main_GUI = GUICreate("Drag & Drop LV Item", 225, 400, -1, -1, BitOR($WS_THICKFRAME, $WS_SIZEBOX))

$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, $LVS_SINGLESEL)
$h_ListView = GUICtrlGetHandle($ListView)

_GUICtrlListView_SetColumnWidth($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth($ListView, 1, 100)

GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES)

GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_SUBITEMIMAGES)

$h_ImageList = _GUIImageList_Create(20, 20, 5, 0, 4, $LVSIL_SMALL)

For $i = 0 To 10
    _GUIImageList_AddIcon($h_ImageList, @SystemDir & "\shell32.dll", $i)
Next

_GUICtrlListView_SetImageList($h_ListView, $h_ImageList, $LVSIL_SMALL)

For $i = 0 To 9
    GUICtrlCreateListViewItem("Name " & $i & "|Category " & $i, $ListView)
    _GUICtrlListView_SetItemImage($h_ListView, $i, $i, 0); listview handle, index, subitem, image index
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_EVENTS")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP_EVENTS")
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE_EVENTS")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUIImageList_Destroy($h_ImageList)
            Exit
    EndSwitch
WEnd

Func WM_LBUTTONUP_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    $bDragging = False

    DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $h_ListView, "ptr", 0, "int", 0, "int", 5)
    $iLast_Index = -1

    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)

    Local $iX = BitAND($lParam, 0xFFFF) - $aLV_Pos[0]
    Local $iY = BitShift($lParam, 16) - $aLV_Pos[1]

    Local $struct_LVHITTESTINFO = DllStructCreate("int;int;uint;int;int;int")

    DllStructSetData($struct_LVHITTESTINFO, 1, $iX)
    DllStructSetData($struct_LVHITTESTINFO, 2, $iY)

    $a_Index[1] = GUICtrlSendMsg($ListView, $LVM_HITTEST, 0, DllStructGetPtr($struct_LVHITTESTINFO))
    Local $iFlags = DllStructGetData($struct_LVHITTESTINFO, 2)

;// Out of the ListView?
    If $a_Index[1] == -1 Then Return $GUI_RUNDEFMSG

;// Not in an item?
    If BitAND($iFlags, $LVHT_ONITEMLABEL) == 0 And BitAND($iFlags, $LVHT_ONITEMSTATEICON) == 0 Then Return $GUI_RUNDEFMSG

    If $a_Index[0] <> $a_Index[1] Then
;ConsoleWrite($a_Index[0] & " ==> " & $a_Index[1] & @CRLF)
        _GUICtrlListView_CopyItem($h_ListView, $h_ListView, $a_Index[0], $a_Index[1], 1)
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_LBUTTONUP_EVENTS

Func WM_MOUSEMOVE_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    If Not $bDragging Or $drawing Then Return $GUI_RUNDEFMSG

    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)

    Local $iX = BitAND($lParam, 0xFFFF) - $aLV_Pos[0]
    Local $iY = BitShift($lParam, 16) - $aLV_Pos[1]

    Local $struct_LVHITTESTINFO = DllStructCreate("int;int;uint;int;int;int")

    DllStructSetData($struct_LVHITTESTINFO, 1, $iX)
    DllStructSetData($struct_LVHITTESTINFO, 2, $iY)

    Local $iItem = GUICtrlSendMsg($ListView, $LVM_HITTEST, 0, DllStructGetPtr($struct_LVHITTESTINFO))
    If $iItem = -1 Then Return $GUI_RUNDEFMSG

    If $iLast_Index = $iItem Then Return $GUI_RUNDEFMSG

    If $iLast_Index > $iItem Then;Move up
        _GUICtrlListView_RedrawItems($ListView, $iItem, $iLast_Index)
    Else
        _GUICtrlListView_RedrawItems($ListView, $iLast_Index, $iItem - 1)
    EndIf

    $iLast_Index = $iItem

    Local $aLV_Pos = ControlGetPos($hWndGUI, "", $ListView)
    Local $iY = _GUICtrlListView_GetItemPositionY($ListView, $iItem)

    If $iY <= 0 Then Return $GUI_RUNDEFMSG

    _DrawLine($aLV_Pos[0], $iY, $aLV_Pos[2], 3, 0xFF0000, $h_ListView)
EndFunc ;==>WM_MOUSEMOVE_EVENTS

Func WM_NOTIFY_EVENTS($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $iEvent, $hwndFrom, $iCode, $iItem

    $tagNMHDR = DllStructCreate("int;int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code, Item)
    If @error Then Return $GUI_RUNDEFMSG

    $iCode = DllStructGetData($tagNMHDR, 3)
    $iItem = DllStructGetData($tagNMHDR, 4)

    Switch $wParam
        Case $ListView
            Switch $iCode
                Case $LVN_BEGINDRAG
                    $a_Index[0] = $iItem
                    $bDragging = True

                    _GUICtrlListView_SetItemSelected($ListView, $iItem, False)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY_EVENTS

Func _GUICtrlListView_CopyItem($hWnd_Source, $hWnd_Destination, $iSrcIndex, $iDstIndex, $fDelFlag = False)
    Local $iInsert_Index
    Local $tItem = DllStructCreate($tagLVITEM)

    Local $iCols = _GUICtrlListView_GetColumnCount($hWnd_Source)
    Local $iItems = _GUICtrlListView_GetItemCount($hWnd_Source)
    Local $iDest_Items = _GUICtrlListView_GetItemCount($hWnd_Destination)

    _GUICtrlListView_BeginUpdate($hWnd_Source)
    If $hWnd_Destination <> $hWnd_Source Then _GUICtrlListView_BeginUpdate($hWnd_Destination)

    DllStructSetData($tItem, "Mask", BitOR($LVIF_GROUPID, $LVIF_IMAGE, $LVIF_INDENT, $LVIF_PARAM, $LVIF_STATE))
    DllStructSetData($tItem, "Item", $iSrcIndex)
    DllStructSetData($tItem, "SubItem", 0)
    DllStructSetData($tItem, "StateMask", -1)

    _GUICtrlListView_GetItemEx($hWnd_Source, $tItem)

    If $iDstIndex > $iSrcIndex Then
        $iDstIndex += 1
    ElseIf $iSrcIndex > $iDstIndex Then
        $iSrcIndex += 1
    EndIf

    $iInsert_Index = _GUICtrlListView_InsertItem($hWnd_Destination, _
            _GUICtrlListView_GetItemText($hWnd_Source, $iSrcIndex, 0), $iDstIndex, DllStructGetData($tItem, "Image"))

    If BitAND(_GUICtrlListView_GetExtendedListViewStyle($hWnd_Source), $LVS_EX_CHECKBOXES) == $LVS_EX_CHECKBOXES Then
        If _GUICtrlListView_GetItemChecked($hWnd_Source, $iSrcIndex) Then _
                _GUICtrlListView_SetItemChecked($hWnd_Destination, $iInsert_Index)
    EndIf

    For $i = 0 To $iCols - 1
        DllStructSetData($tItem, "Item", $iInsert_Index)
        DllStructSetData($tItem, "SubItem", $i)

        _GUICtrlListView_GetItemEx($hWnd_Source, $tItem)

        _GUICtrlListView_AddSubItem($hWnd_Destination, $iInsert_Index, _
                _GUICtrlListView_GetItemText($hWnd_Source, $iSrcIndex, $i), $i, DllStructGetData($tItem, "Image"))
    Next

    If $fDelFlag Then _GUICtrlListView_DeleteItem($hWnd_Source, $iSrcIndex)

    If $iDstIndex > $iSrcIndex Then $iDstIndex -= 1
    _GUICtrlListView_SetItemSelected($hWnd_Source, $iDstIndex)

    _GUICtrlListView_EndUpdate($hWnd_Source)
    If $hWnd_Destination <> $hWnd_Source Then _GUICtrlListView_EndUpdate($hWnd_Destination)

    _GUICtrlListView_RedrawItems($hWnd_Destination, $iSrcIndex, $iDstIndex)
;DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $hWnd_Destination, "ptr", 0, "int", 0, "int", 5)
EndFunc ;==>_GUICtrlListView_CopyItem

Func _DrawLine($iLeft, $iTop, $iWidth, $iHeight, $sColor, $hWnd = 0)
    $drawing = True
    $sColor = Hex("0x" & BitAND(BitShift(String(Binary($sColor)), 8), 0xFFFFFF));RGB2BGR

    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iHeight, "int", $sColor)

    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    ConsoleWrite("drawline " & $iLastLineLeft & ', ' & $iLastLinetop & ', ' & $iLeft & ', ' & $iTop & @CRLF)
    If $iLastLinetop > -1 And $iLastLineLeft > -1 Then
        If $iLastLinetop <> $iTop Then; or $iLastLineLeft <> $iLeft Then
            Local $strRect = DllStructCreate("int[4]")

            DllStructSetData($strRect, 1, 5)
            DllStructSetData($strRect, 2, 75)
            DllStructSetData($strRect, 3, 198 + 5)
            DllStructSetData($strRect, 4, 280 + 75)
            Local $pRect = DllStructGetPtr($strRect)
            $iLastLineLeft = $iLeft
            $iLastLinetop = $iTop
            DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($ListView), "int", 0, "int", 1)
            Sleep(50);seems to be needed to ensure redrawn before line is drawn
        EndIf
    EndIf

    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft + $iWidth, "int", $iTop)

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
    DllCall("GDI32.dll", "int", "DeleteObject", "int", $aPen[0])
    $drawing = False
EndFunc ;==>_DrawLine
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks martin! it works well.

I will try to fix the issue with last item, and also there is issue with CopyItem function call, sometimes it's not called, even if the item is above/bellow other item.

 

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

Link to comment
Share on other sites

  • 11 years later...
  • Moderators

@Verssuss please don't resurrect old threads - it has been almost 12 years since this question was asked, I highly doubt the user is still waiting for an answer.

"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

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
 Share

  • Recently Browsing   0 members

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