Jump to content

How to drag file reference to another application?


qwert
 Share

Recommended Posts

Based on methods outlined in these forums, a ListView item can be dragged to another control ... and seems to be the easiest way to drag and drop content.  (Below is a working example.)

But I've run upon two problems:

1. The orange arrow points to a "bar" character that is appended to the file name when I drag to a control on the same window.  What is causing that?

2. Any other application window (even one of my own) rejects the drop of the ListView item (sounds a "ding").   Yet, my own (other) GUI can accept a file from a file manager, for example ... as can this example GUI.  What determines a window's "drag enabled" status? (i.e., as a source of files)

Thanks in advance to anyone who can point me to examples or explanations.

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

$hGUI = GUICreate("Move Input Anywhere Example", 400, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
$hInput = GUICtrlCreateInput("C:\Temp\RichNote.rtf", 10, 120, 320, 24)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

$ListView = GUICtrlCreateListView("", 20, 20, 360, 80)
GUICtrlSetFont(-1, 11, 400, 0, "Tahoma")
_GUICtrlListView_AddColumn($ListView, "File Link:", 340)
GUICtrlCreateListViewItem("C:\Temp\RichNote.rtf", $ListView)

GUISetState()

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

DragDrop.png.cc4c3379615781e60bd185bf9c2bfe7a.png

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Sorry for the late response.  I've been working on quite a few other things.

Regarding the bar: it's really a bar character, not a blinking caret cursor.  If I Ctrl+C copy the contents, there's actually a bar character at the end.

And my second question still stands, as well.  Both of these issues are unexpected hurdles to smooth GUI operation.   I don't mind adhering to rules, but what/where ARE the rules?

 

Link to comment
Share on other sites

  1. Is a pipe to separate the columns, so try the following this gets around the issue by replacing the text prior to being dropped:
    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    
    $hGUI = GUICreate("Move Input Anywhere Example", 400, 140, -1, -1, -1, $WS_EX_ACCEPTFILES)
    $idListView = GUICtrlCreateListView("FileLink:", 10, 10, 380, 80, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
        GUICtrlCreateListViewItem("C:\Temp\RichNote.rtf", $idListView)
        _GUICtrlListView_SetColumnWidth($idListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
        GUICtrlSetFont(-1, 11, 400, 0, "Tahoma")
    $idInput = GUICtrlCreateInput("", 10, 100, 380, 20)
        GUICtrlSetState($idInput, $GUI_DROPACCEPTED)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_DROPPED
                If @GUI_DropId = $idInput Then
                    GuiCtrlSetData($idInput, StringReplace(GUICtrlRead($idInput), "|", "") )
                EndIf
        EndSwitch
    WEnd

     

  2. This has been discussed previously in other posts, its something to do with Handling OLE DragDrop Events (see link below).
    nb: You can actually drag and drop from RichEdit boxes externally.

 

Link to comment
Share on other sites

@Subz, thanks for looking at this.  That's a good solution ... and the UDF is something I'll explore.  Rich edits open a large set of capabilities for a GUI.  It's nice to get some of these secondary issues under control.

I appreciate your help.

 

5b21a37b5aac5_Nicesolution.PNG.7d69890f1d5b56d1d35dd5a18fb77d32.PNG

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