Drag & Drop von LV zu LV

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Drag & Drop von LV zu LV

18 Jul 2017, 05:35

Hi,

ist es möglich... (wahrscheinlich geht das wieder an 'just me', habe allerdings nichts auf die schnelle in deinen Sammlungen gefunden)

Eine Gui mit 2 ListView's.
Von LV2 (eine Spalte) einen Eintrag (oder mehrere markierte) per Drag & Drop in die LV1 ziehen, dabei abfangen was in dem Eintrag stand und ggf. irgendwas machen und LV1 neu befüllen.

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
#NoTrayIcon

SetBatchLines -1

global WinVersion := RtlGetVersion()

; GUI ===========================================================================================================================

Gui, +hWndhMainGUI
Gui, Margin, 10, 10
Gui, Font, s9, Segoe UI

Gui, Add, ListView, xm   ym w500 h400 vMyLV1 hWndhMyLV1 +LV0x14000, % "A|B|C|D|E"
if (WinVersion >= 0x0600)
    SetWindowTheme(hMyLV1)

Gui, Add, ListView, x+10 yp w200 h400 vMyLV2 hWndhMyLV2 +LV0x14000, % "F"
if (WinVersion >= 0x0600)
    SetWindowTheme(hMyLV2)
Loop, Files, % A_WinDir "\system32\*.dll"
    LV_Add("", A_LoopFileName)

Gui, Show, AutoSize
HideFocusBorder(hMainGUI)
return

; SCRIPT ========================================================================================================================

GuiDropFiles:
    LV_Delete()
    ; ....
return

; FUNCTIONS =====================================================================================================================

RtlGetVersion()
{
    static RTL_OSV_EX, init := NumPut(VarSetCapacity(RTL_OSV_EX, A_IsUnicode ? 284 : 156, 0), RTL_OSV_EX, "uint")
    if (DllCall("ntdll\RtlGetVersion", "ptr", &RTL_OSV_EX) != 0)
        throw Exception("RtlGetVersion failed", -1)
    return ((NumGet(RTL_OSV_EX, 4, "uint") << 8) | NumGet(RTL_OSV_EX, 8, "uint"))
}

SetWindowTheme(handle)
{
    if (HRESULT := DllCall("uxtheme\SetWindowTheme", "ptr", handle, "wstr", "Explorer", "ptr", 0) != 0)
        throw Exception("SetWindowTheme failed: " HRESULT, -1)
    return true
}

HideFocusBorder(wParam, lParam := "", Msg := "", handle := "") ; by 'just me'
{
    static Affected         := []
    static WM_UPDATEUISTATE := 0x0128
    static SET_HIDEFOCUS    := 0x00010001 ; UIS_SET << 16 | UISF_HIDEFOCUS
    static init             := OnMessage(WM_UPDATEUISTATE, Func("HideFocusBorder"))

    if (Msg = WM_UPDATEUISTATE) {
        if (wParam = SET_HIDEFOCUS)
            Affected[handle] := true
        else if Affected[handle]
            DllCall("user32\PostMessage", "ptr", handle, "uint", WM_UPDATEUISTATE, "ptr", SET_HIDEFOCUS, "ptr", 0)
    }
    else if (DllCall("IsWindow", "ptr", wParam, "uint"))
        DllCall("user32\PostMessage", "ptr", wParam, "uint", WM_UPDATEUISTATE, "ptr", SET_HIDEFOCUS, "ptr", 0)
}

; EXIT ==========================================================================================================================

GuiClose:
GuiEscape:
ExitApp

; ===============================================================================================================================
jNizM
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Drag & Drop von LV zu LV

18 Jul 2017, 10:59

Hallo jNizM,

cut/copy/paste über ein Contextmenü ist mit Sicherheit die einfachere Alternative, wirkt aber vielleicht nicht so 'elegant'.

Ich bin mir sicher, dass es für D&D zwischen zwei ListViews schon Skripte gibt, zumindest im alten Forum. Ich habe die allerdings gerade auch nicht parat.

Ich habe mich damit selbst noch nicht beschäftigt, aber über IDropSource/IDropTarget sollte das machbar sein. Wenn sich beide in einem Skript befinden, ist ja Alles unter Kontrolle.

Grüße, just me
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Drag & Drop von LV zu LV

19 Jul 2017, 01:13

Hey,

ok.. so wie es aussieht gibt es dann wohl keinen 10-20 Zeiler dafür :D

Edit:
Hab was in au3 gefunden. Bisschen umschreiben und dann sollte es doch nützlich sein...

Code: Select all

Dim $LISTVIEW_ITEM[10]

$GUI = GUICreate("Drag'n'Drop",800,600,-1,-1)
$LISTVIEW_LEFT = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4",0,0,400,600)
GUICtrlSetState(-1, 8) ; $GUI_DROPACCEPTED = 8

For $i = 0 To 9
    $LISTVIEW_ITEM[$i] = GUICtrlCreateListViewItem("Item "&$i,$LISTVIEW_LEFT)
Next

$LISTVIEW_RIGHT = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4",400,0,400,600)
GUICtrlSetState(-1, 8) ; $GUI_DROPACCEPTED = 8

GUISetState(@SW_SHOW)

While True
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case -13
            MoveItem(@GUI_DragId, @GUI_DropId)
    EndSwitch
WEnd

Func MoveItem($drag, $drop)
    GUICtrlCreateListViewItem(GUICtrlRead(GUICtrlRead($drag)), $drop)
    GUICtrlDelete(GUICtrlRead($drag))
EndFunc
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Drag & Drop von LV zu LV

19 Jul 2017, 02:19

Listview drag/drop items - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=2072

Dieses Skript ist ziemlich gut. [Goo.Tra.]
[This script is pretty good.]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Drag & Drop von LV zu LV

19 Jul 2017, 02:30

Das Problem ist, dass AHK das 'draggen' von ListView Items nicht selbst unterstützt:
D: The user has attempted to start dragging a row or icon (there is currently no built-in support for dragging rows or icons). The variable A_EventInfo contains the focused row number. In v1.0.44+, this notification occurs even without AltSubmit.
Da hilft es dann auch nicht, den Controls irgendwelche Eigenschaften zuzuordnen.

AutoIt tut das anscheinend:
If $GUI_DROPACCEPTED (8) is set to a visible control a drag & drop can be taken in account. The edit/input control will be set with the filename.
For other controls on reception of $GUI_EVENT_DROPPED, @GUI_DragId will return the controlID from where the drag start (-1 if from a file, @GUI_DragFile contain the filename being dropped) and @GUI_DropId returns the controlID of the dropped control.
Only dragging a ListviewItem will start the drag & drop process. The @GUI_DragId will be the ListView controlID.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Drag & Drop von LV zu LV

19 Jul 2017, 02:49

Sollte das dann nicht mal als Request an den Herrn l. gehen?

edit: L -> l :D
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Drag & Drop von LV zu LV

19 Jul 2017, 03:12

Wenn Du der Meinung bist, er könnte daran 'interessiert' sein, kannst Du es ja mal versuchen. Vielleicht macht er das dann für AHK v3. ;)

(Übrigens: "Herr L." schreibt sich mit kleinem "l", und er legt Wert darauf!)
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Drag & Drop von LV zu LV

19 Jul 2017, 05:20

Jetzt hab ich aber ein anderes Problem...
Ich packs hier einfach mal dazu:

Wenn ich im LV2 mit Rechtsklick (Kontextmenu) auf Load drücke übergibt er die Daten ins LV1. Allerdings lässt sich kein weiterer Rechtsklick auf LV2 betätigen.
Wenn ich die Daten nicht an LV1 überbebe, kann ich mehrmals Rechtsklick auf LV2 machen und es klappt. Als ob er hier das Menu nicht richtig abschließen kann.

Jemand ne Idee?

Code: Select all

GuiContextMenu:
    if (A_GuiControl = "MyLV1") && (LV_GetNext() > 0) {
        Menu, ContextMenuA, Add, % "Copy`tCtrl+C", ContextCopy
        Menu, ContextMenuA, Show, % A_GuiX, % A_GuiY
    }
    if (A_GuiControl = "MyLV2") && (LV_GetNext() > 0) {
        Menu, ContextMenuB, Add, % "Load", ContextLoad
        Menu, ContextMenuB, Show, % A_GuiX, % A_GuiY
    }
return

ContextCopy:
    ColNum := LVM_SUBITEMHITTEST(hMyLV)
    ControlGet, List, List, Selected Col%ColNum%, SysListView321, % "ahk_id " hMainGUI
    Clipboard := List
return

ContextLoad:
    ControlGet, FileName, List, Selected Col1, SysListView322, % "ahk_id " hMainGUI
    DllFile := A_WinDir "\system32\" FileName
    Goto LV_Load
return
Edit:
Mein Fehler... Bei LV_xxx() befehlen sollte man vorher angeben welches LV benutzt wird... (hier war es bei LV_GetNext)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 28 guests