Sign in to follow this  
Followers 0
ReFran

@Gui_DragFile(s) on a Listview

7 posts in this topic

Hello,

I wanted to Drag&Drop mulitple files on a listview, but with @Gui_DragFile I got only one file.

Is there a funktion like @Gui_DragFiles, a for loop, an array variable or something else.

Attached the listview example from help file with added Drag&Drop function.

Best regards, Reinhard

#include <GUIConstants.au3>

GUICreate("listview items",220,250, 100,200,-1,$WS_EX_ACCEPTFILES)
GUISetBkColor (0x00E0FFFF) ; will change background color

$listview = GuiCtrlCreateListView ("col1  |col2|col3  ",10,10,200,150);,$LVS_SORTDESCENDING)
GuiCtrlSetState(-1,$GUI_DROPACCEPTED)  ; to allow drag and dropping
$button = GuiCtrlCreateButton ("Value?",75,170,70,20)
$item1=GuiCtrlCreateListViewItem("item2|col22|col23",$listview)
$item2=GuiCtrlCreateListViewItem("............item1|col12|col13",$listview)
$item3=GuiCtrlCreateListViewItem("item3|col32|col33",$listview)
$input1=GuiCtrlCreateInput("",20,200, 150)
GuiCtrlSetState(-1,$GUI_DROPACCEPTED)  ; to allow drag and dropping
GuiSetState()
GUICtrlSetData($item2,"|ITEM1")
GUICtrlSetData($item3,"||COL33")
GUICtrlDelete($item1)

Do
  $msg = GuiGetMsg ()
     
   Select
      Case $msg = $button
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview)),2)
      Case $msg = $GUI_EVENT_DROPPED     
           msgbox(0,"","DragID: "&@GUI_DragId & "DropID: " &@gui_dropID &@crlf &"DropFile:"& @gui_dragfile)
         
         
      Case $msg = $listview
         MsgBox(0,"listview", "clicked="& GuiCtrlGetState($listview),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites



Thanks for the link.

A workaround with an editbox I have already.

I want to get a solution to drag multiple files direct on a LV.

Seems not to be possible at time.

Best regards, Reinhard

Share this post


Link to post
Share on other sites

Thanks for the link.

A workaround with an editbox I have already.

I want to get a solution to drag multiple files direct on a LV.

Seems not to be possible at time.

Best regards, Reinhard

Now possible, modified lazycat's code for a List to work with ListView

#include <GUIConstants.au3>
#include <GuiListView.au3>

Opt("MustDeclareVars", 1)

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]

_Main()

Func _Main()
    Local $hGUI, $hListview, $nMsg
    $hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
    $hListview = GUICtrlCreateListView("File(s)", 5, 5, 390, 190)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    _GUICtrlListViewSetColumnWidth($hListview, 0, $LVSCW_AUTOSIZE_USEHEADER)
    GUISetState(@SW_SHOW)
    
    GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_DROPPED
                _GUICtrlListViewDeleteAllItems($hListview)
                For $i = 0 To UBound($gaDropFiles) - 1
                    GUICtrlCreateListViewItem($gaDropFiles[$i], $hListview)
                Next
        EndSwitch
    WEnd
EndFunc   ;==>_Main

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

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Now possible, modified lazycat's code for a List to work with ListView

Oh, you remember to this. Thank you.

I played already a little bit around with the code based on a question you answered for tab on tab, because I need it for tab on tab. I puzzled both together, but have one question to it: How it is possible to start the script with focus on Tab0?

Now it always start with focus on tab2 (like that one in the helpfile).

Best regards, Reinhard

#include <GUIConstants.au3>
#include <GuiListView.au3>

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]



$Main_Gui = GUICreate("MAINs",500,250, 50,50,-1,$WS_EX_ACCEPTFILES)  ; will create a dialog box that when displayed is centered

$Child_Gui = GUICreate("Child Gui", 480, 460, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $Main_Gui)
    $child_tab = GUICtrlCreateTab(10, 10, 470, 450)
    $c_tab0 = GUICtrlCreateTabItem("c_tab0")
    $button = GUICtrlCreateButton("test button", 20, 40, 120, 25)
    $c_tab1 = GUICtrlCreateTabItem("c_tab1")
GUICtrlCreateTabItem("")   ; end tabitem definition

GUISwitch($Main_Gui)

GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)

$tab = GUICtrlCreateTab(10, 10, 490, 490)

$tab0 = GUICtrlCreateTabItem("tab0")
;GUICtrlCreateLabel("label0", 30, 80, 50, 20)
;$tab0OK = GUICtrlCreateButton("OK0", 20, 50, 50, 20)
;$tab0input = GUICtrlCreateInput("default", 80, 50, 70, 20)
$listview = GUICtrlCreateListView ("Files",20,40,450,150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)   ; to allow drag and dropping
_GUICtrlListViewSetColumnWidth($Listview, 0, $LVSCW_AUTOSIZE_USEHEADER)

$tab1 = GUICtrlCreateTabItem("tab1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
$tab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
$tab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $GUI_SHOW)   ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
$tab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)

$tab3 = GUICtrlCreateTabItem("tab3")
GUICtrlCreateTabItem("")   ; end tabitem definition


GUISetState()
GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_EVENT_DROPPED
         _GUICtrlListViewDeleteAllItems($listview)
         For $i = 0 To UBound($gaDropFiles) - 1
            $nItem = GUICtrlCreateListViewItem($gaDropFiles[$i],$listview)
            next
        Case $msg = $tab
             If GUICtrlRead($tab) = 3 Then
                GUISetState(@SW_SHOW, $Child_Gui)
             Else
                GUISetState(@SW_HIDE, $Child_Gui)
             EndIf
    EndSelect
    
WEnd

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) 
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i+1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc
Edited by ReFran

Share this post


Link to post
Share on other sites

GuiCtrlSetState

#include <GUIConstants.au3>
#include <GuiListView.au3>

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]



$Main_Gui = GUICreate("MAINs",500,250, 50,50,-1,$WS_EX_ACCEPTFILES)  ; will create a dialog box that when displayed is centered

$Child_Gui = GUICreate("Child Gui", 480, 460, 15, 35, BitOR($WS_CHILD, $WS_TABSTOP), -1, $Main_Gui)
    $child_tab = GUICtrlCreateTab(10, 10, 470, 450)
    $c_tab0 = GUICtrlCreateTabItem("c_tab0")
    $button = GUICtrlCreateButton("test button", 20, 40, 120, 25)
    $c_tab1 = GUICtrlCreateTabItem("c_tab1")
GUICtrlCreateTabItem("")   ; end tabitem definition

GUISwitch($Main_Gui)

GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)

$tab = GUICtrlCreateTab(10, 10, 490, 490)

$tab0 = GUICtrlCreateTabItem("tab0")
;GUICtrlCreateLabel("label0", 30, 80, 50, 20)
;$tab0OK = GUICtrlCreateButton("OK0", 20, 50, 50, 20)
;$tab0input = GUICtrlCreateInput("default", 80, 50, 70, 20)
$listview = GUICtrlCreateListView ("Files",20,40,450,150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)   ; to allow drag and dropping
_GUICtrlListViewSetColumnWidth($Listview, 0, $LVSCW_AUTOSIZE_USEHEADER)

$tab1 = GUICtrlCreateTabItem("tab1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
$tab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
$tab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)

$tab2 = GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $GUI_SHOW)   ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
$tab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)

$tab3 = GUICtrlCreateTabItem("tab3")
GUICtrlCreateTabItem("")   ; end tabitem definition
GUICtrlSetState($tab0, $GUI_SHOW)

GUISetState()
GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_EVENT_DROPPED
         _GUICtrlListViewDeleteAllItems($listview)
         For $i = 0 To UBound($gaDropFiles) - 1
            $nItem = GUICtrlCreateListViewItem($gaDropFiles[$i],$listview)
            next
        Case $msg = $tab
             If GUICtrlRead($tab) = 3 Then
                GUISetState(@SW_SHOW, $Child_Gui)
             Else
                GUISetState(@SW_HIDE, $Child_Gui)
             EndIf
    EndSelect
    
WEnd

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

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Works fine. I tried only GUISwitch.

Thanks, Reinhard

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