Sign in to follow this  
Followers 0
edthedestroyer

Drag & Drop then copy file (Solved)

6 posts in this topic

#1 ·  Posted (edited)

I'm trying to create an interface where users drag a file (a picture) into the window, and the file is copied to a new location for further use in the main program.

Func drag() ;window for receiving drag and drop pictures.
    $winhand2 = GUICreate("Drag Photo Here",200,200,0,-1,-1, $WS_EX_ACCEPTFILES)
    $file=0
    $edit1=GUICtrlCreateEdit("", 10,30,180,160,$ES_AUTOVSCROLL)
    GUICtrlSetState(-1,$GUI_DROPACCEPTED)
    
    GUISetState()
    
    while (1)
        
        $msg=Guigetmsg()
        
        switch $msg
            
        case $GUI_EVENT_CLOSE
            ExitLoop
            
        case $GUI_EVENT_DROPPED
            MsgBOx(64,"",@GUI_DRAGFILE) ;shows me that the correct filepath was imported
            $ee=FileCopy(@GUI_DRAGFILE,@MyDocumentsDir & "\tempscr.bmp",9)
            MsgBOx(64,"",$ee) ;tells me if the filecopy fails, it always does
            ExitLoop
        EndSwitch
    Wend
    
        GUIDelete() 
EndFunc

The problem is, the script will not copy the file. It has the correct filepath but the copy always fails. It's as if the file is being used and can't be copied when you drag and drop the file.

Solution: @GUI_DRAGFILE contains a @CRFL which needed to be removed before FileCopy can find the source.

FileCopy(StringReplace(@GUI_DRAGFILE,@CRLF,""),@MyDocumentsDir & "\tempscr.bmp",9)

Thanks Aipion!

Edited by edthedestroyer

Share this post


Link to post
Share on other sites



Path to Truth starts here: http://ap.freewey.com

You can publish your links at the page "Your site".

Share this post


Link to post
Share on other sites

Thank you spambot.

If I put the filepath in the filecopy it works just fine. But if the pathfile is pulled for @GUI_DRAGEFILE which appears to be the exact same string, the filecopy fails. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

When you Drag & Drop a file, the @GUI_DRAGFILE has the file path with a @CRLF. so you have to just remove it then it will work.

This should Work:

Func drag() ;window for receiving drag and drop pictures.
    $winhand2 = GUICreate("Drag Photo Here",200,200,0,-1,-1, $WS_EX_ACCEPTFILES)
    $file=0
    $edit1=GUICtrlCreateEdit("", 10,30,180,160,$ES_AUTOVSCROLL)
    GUICtrlSetState(-1,$GUI_DROPACCEPTED)
   
    GUISetState()
   
    while (1)
       
        $msg=Guigetmsg()
       
        switch $msg
           
        case $GUI_EVENT_CLOSE
            ExitLoop
           
        case $GUI_EVENT_DROPPED
            MsgBOx(64,"",@GUI_DRAGFILE) ;shows me that the correct filepath was imported
            $ee=FileCopy(StringReplace(@GUI_DRAGFILE,@CRLF,""),@MyDocumentsDir & "tempscr.bmp",9)
            MsgBOx(64,"",$ee) ;tells me if the filecopy fails, it always does
            ExitLoop
        EndSwitch
    Wend
   
        GUIDelete()
EndFunc

Share this post


Link to post
Share on other sites

o_0

Do you have a script for getting the past hour of my life back?

Thanks very much.

Share this post


Link to post
Share on other sites

o_0

Do you have a script for getting the past hour of my life back?

Thanks very much.

No But i hope there is one in the future. LOL

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
Sign in to follow this  
Followers 0