1 | ; Includes first! Must must must! |
---|
2 | #include <GUIConstantsEx.au3> |
---|
3 | #include <ListViewConstants.au3> |
---|
4 | #Include <GuiListView.au3> |
---|
5 | #include <StaticConstants.au3> |
---|
6 | #include <WindowsConstants.au3> |
---|
7 | #include <Array.au3> |
---|
8 | #include <Misc.au3> |
---|
9 | |
---|
10 | |
---|
11 | ; Switch on the 'onEvent' notifications |
---|
12 | Opt ("GUIOnEventMode", 1) |
---|
13 | |
---|
14 | |
---|
15 | ; Generate the GUI! Ahoy there. |
---|
16 | Global $MainForm, $list_source, $list_target |
---|
17 | $MainForm = GUICreate(" TEST! ", 517, 178) |
---|
18 | |
---|
19 | |
---|
20 | ; Source list box |
---|
21 | $list_source = GUICtrlCreateListView("Title|Details", 13, 16, 240, 136, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) |
---|
22 | |
---|
23 | |
---|
24 | ; Target list box |
---|
25 | $list_target = GUICtrlCreateListView("Title|Details", 261, 16, 240, 136, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) |
---|
26 | |
---|
27 | |
---|
28 | ; Populate box with some test stuff |
---|
29 | For $x = 1 to 6 |
---|
30 | GUICtrlCreateListViewItem( _makeJunkName() & "|" & _makeJunkName(), $list_source) |
---|
31 | Next |
---|
32 | |
---|
33 | |
---|
34 | ; Handle GUI events |
---|
35 | GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_dragHandler") |
---|
36 | GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents") |
---|
37 | GUISetOnEvent($GUI_EVENT_MINIMIZE, "_formEvents") |
---|
38 | GUISetOnEvent($GUI_EVENT_RESTORE, "_formEvents") |
---|
39 | |
---|
40 | |
---|
41 | ; Show the form |
---|
42 | GUISetState(@SW_SHOW) |
---|
43 | |
---|
44 | |
---|
45 | ; Main program loop |
---|
46 | While 1 |
---|
47 | ; Don't really do much in here at all... |
---|
48 | WEnd |
---|
49 | |
---|
50 | |
---|
51 | ; Create a junk name for testing |
---|
52 | Func _makeJunkName() |
---|
53 | Local $labelout = '' |
---|
54 | For $i = 1 to 10 |
---|
55 | $labelout &= chr(Random(65,90,1)) |
---|
56 | Next |
---|
57 | Return $labelout |
---|
58 | EndFunc |
---|
59 | |
---|
60 | |
---|
61 | ; Function to handle drag and drop |
---|
62 | Func _dragHandler() |
---|
63 | |
---|
64 | ; Define some stuff |
---|
65 | Local $source, $desc |
---|
66 | Local $cinfo = GUIGetCursorInfo (WinGetHandle($MainForm)) |
---|
67 | Local $direction = 0 |
---|
68 | |
---|
69 | ; Check we are dragging from one or the other boxes |
---|
70 | If $cinfo[4] = $list_source OR $cinfo[4] = $list_target Then |
---|
71 | |
---|
72 | ; Are we moving from source to destination |
---|
73 | If $cinfo[4] = $list_source Then |
---|
74 | $direction = 1 |
---|
75 | EndIf |
---|
76 | |
---|
77 | ; Or are we moving from destination to source |
---|
78 | If $cinfo[4] = $list_target Then |
---|
79 | $direction = 2 |
---|
80 | EndIf |
---|
81 | |
---|
82 | ; Doublecheck we're pressing mouse button |
---|
83 | If _IsPressed(1) Then |
---|
84 | if $direction = 1 Then |
---|
85 | $selecteditems = _GUICtrlListView_GetSelectedCount($list_source); |
---|
86 | Else |
---|
87 | $selecteditems = _GUICtrlListView_GetSelectedCount($list_target); |
---|
88 | EndIf |
---|
89 | |
---|
90 | ; Check we actually have selected an item |
---|
91 | If $selecteditems >= 1 Then |
---|
92 | |
---|
93 | ; Wait for keypress! |
---|
94 | While _IsPressed(1) |
---|
95 | WEnd |
---|
96 | |
---|
97 | ; Get new position |
---|
98 | Local $newcinfo = GUIGetCursorInfo (WinGetHandle($MainForm)) |
---|
99 | |
---|
100 | ; If we were moving from source to destination and we ARE in the destination box |
---|
101 | If $direction = 1 And $newcinfo[4] = $list_target Then |
---|
102 | ConsoleWrite("Moved " & $selecteditems & " items from source to destination" & @CRLF) |
---|
103 | _GUICtrlListView_CopyItems ($list_source, $list_target, 1) |
---|
104 | EndIf |
---|
105 | |
---|
106 | ; If we are moving from destination to source and we ARE in source box |
---|
107 | If $direction = 2 And $newcinfo[4] = $list_source Then |
---|
108 | ConsoleWrite("Moved " & $selecteditems & " items from destination to source" & @CRLF) |
---|
109 | _GUICtrlListView_CopyItems ($list_target, $list_source, 1) |
---|
110 | EndIf |
---|
111 | |
---|
112 | EndIf |
---|
113 | |
---|
114 | EndIf |
---|
115 | |
---|
116 | EndIf |
---|
117 | |
---|
118 | EndFunc |
---|
119 | |
---|
120 | |
---|
121 | ; Function to handle other form events |
---|
122 | Func _formEvents() |
---|
123 | Select |
---|
124 | Case @GUI_CtrlId = $GUI_EVENT_CLOSE |
---|
125 | Exit |
---|
126 | EndSelect |
---|
127 | EndFunc |
---|