Jump to content

ListView, drag&drop and on event


stoyan
 Share

Recommended Posts

Hello, all!

I've got a list view control. It has to accepts a drag/dropped files from the Explorer. Then I have to filter them out and populate the list view. The problem is that list view does not file any event in on event mode. At least on my side. The closest thing I found on the forums is this answer. A slightly modified (on message) version is working ok, at least events are being fired. Here is the working (edited from the post above) script:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$parent = GUICreate("test",200,200,-1,-1,-1,$WS_EX_ACCEPTFILES)

GUICtrlCreateListView("Test",10,10,75,75)
GuiCtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetState()
Do
$msg = GUIGetMsg()

if $msg = $GUI_EVENT_DROPPED then
MsgBox(0,"Test",@GUI_DROPID & " " & @GUI_DRAGFILE)
endif

Until $msg = $GUI_EVENT_CLOSE
GuiDelete($parent)

Here is the nonworking mine script:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Opt('GUIOnEventMode', 1)

Global Const $title = 'Some descriptive title'
Global $treff

main()

while 1
    sleep(5000)
wend

func main()

    $treff = GUICreate($title, 500, 385, -1, -1, -1, $WS_EX_ACCEPTFILES)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'handle_close')


    GUICtrlCreateListView('Column one|Column two', 10, 10, 480, 190, $LVS_NOSORTHEADER)
    GuiCtrlSetState(-1, $GUI_DROPACCEPTED)
    GuiCtrlSetOnEvent(-1, 'file_list_event_handler')

    GUISetState()

EndFunc


Func handle_close()
    Switch @GUI_WINHANDLE
        Case $treff
            Exit
    EndSwitch
EndFunc


Func file_list_event_handler()
    MsgBox(48, 'Event status', 'The event has fired!')
EndFunc

I'll need your support.

Edit: fixed the link to the other post

Edited by stoyan

; Opt('MustDeclareVars', 1)

Link to comment
Share on other sites

I had the same problem with listview drag/drop and Opt('GUIOnEventMode')

I think it simply does not work with that combination.

Your best bet is to use GuiGetMsg and find a way to trigger the functions you need that way.

I know

While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_DROPPED
                ListView_Add()
            Case $GUI_EVENT_SECONDARYDOWN
                $extrax = 2
                $extray = 2
                $wpos = WinGetPos($ver)
                $mpos = MouseGetPos()
                $ipos = ControlGetPos($ver, "", $ListView)
                If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
                    ListView_RightClick()
                EndIf
            Case $GUI_EVENT_PRIMARYDOWN
                $extrax = 2
                $extray = 2
                $wpos = WinGetPos($ver)
                $mpos = MouseGetPos()
                $ipos = ControlGetPos($ver, "", $ListView)
                If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
                    If TimerDiff($t) <= 500 And $q = 1 Then
                        ListView_DblClick()
                    Else
                        $t = TimerInit()
                        $q = 1
                    EndIf
                ElseIf $mpos[0] > $wpos[0] + $extrax And $mpos[1] > $wpos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
                    While _IsPressed(01)
                        _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
                    WEnd
                EndIf
        EndSwitch
    WEnd

Worked in my script

*edit*

This snippit uses drag/drop, right click and double click.

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

 stoyan, I've modified a little your script, to handle the drop event:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Opt('GUIOnEventMode', 1)

Global Const $title = 'Some descriptive title'
Global $treff, $hLv,$iLV=0

main()

while 1
    sleep(5000)
wend

func main()

    $treff = GUICreate($title, 500, 385, -1, -1, -1, $WS_EX_ACCEPTFILES)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'handle_close')


    $hLv = GUICtrlCreateListView('Column one|Column two', 10, 10, 480, 190, $LVS_NOSORTHEADER)
    GuiCtrlSetState(-1, $GUI_DROPACCEPTED)
    GuiSetOnEvent($GUI_EVENT_DROPPED, 'file_list_event_handler')


    GUISetState()

EndFunc


Func handle_close()
    Switch @GUI_WINHANDLE
        Case $treff
            Exit
    EndSwitch
EndFunc


Func file_list_event_handler()
    Local $nbv = @GUI_DRAGFILE
    $iLV +=1
    GUICtrlCreateListViewItem($iLV&"|"&$nbv,$hLv)
    ;MsgBox(48, 'Event status', 'The event has fired!')
EndFunc

M.I.

Edited by taietel
Link to comment
Share on other sites

Guess I was wrong ;)

Maybe it was something else then that was blocking the drag/drop, but removing the "oneventmode" worked so I figured that was the problem.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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