JamesPy

Drag and Drop Files to GUICtrlCreateInput

4 posts in this topic

#1 ·  Posted (edited)

I have a simple GUI with two file selection fields. The user can drag a file into Field A, and can drag a file into Field B. Both fields have "C:\" in them to begin with...

Dragging the file to Field A works fine. The pathway and file are displayed correctly.

However Once this is done, when you drag a file into Field B, the path and name are displayed, but are appended with C:\

I realised that the reason being is that when you drag the first file, the focus is on Field A, and the C:\ that is already in the field becomes highlighted as you move the mouse over the GUI.

For Field B, the focus is still on Field A, so it doesn't overwrite the c:\, but appends it to the file name. Here is my code (simplified):

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>


GuiCreate('Test App', 700, 600, @DesktopWidth / 2 - 192, _
            @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)
      
GUICtrlCreateGroup("Dict Files", 5, 5, 570, 90)      
GUICtrlCreateLabel('Select file:', 20, 30)
$dropmpfile = GUICtrlCreateInput ("C:\", 120, 30, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GUICtrlCreateLabel('Select file:', 20, 60)
$droporgfile = GUICtrlCreateInput ("C:\", 120, 60, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')




;GUI MESSAGE LOOP

GuiSetState()
While 1
  $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect 
WEnd

If somebody could help me resolve this I would be really, REALLY grateful!!

 

Thanks in advance - James

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



JamesPy,

What is the point of priming the input control?  The full file path will be dropped.  The following accomplishes the same thing as processing the drop event...

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>

GuiCreate('Test App', 700, 600, @DesktopWidth / 2 - 192, _
            @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)

GUICtrlCreateGroup("Dict Files", 5, 5, 570, 90)
GUICtrlCreateLabel('Select file:', 20, 30)
$dropmpfile = GUICtrlCreateInput ("", 120, 30, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GUICtrlCreateLabel('Select file:', 20, 60)
$droporgfile = GUICtrlCreateInput ("", 120, 60, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')

;GUI MESSAGE LOOP

GuiSetState()
While 1
  $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect
WEnd

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

The OP vanished in the haze like an autumn leaf in the november wind ...  :P

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