Sign in to follow this  
Followers 0
cookiemonster

Drag & Drop Image

7 posts in this topic

#1 ·  Posted (edited)

Hey,

So ive got this script which displays the image in the window, and your meant to be able to drag and drop another .png image file to replace the current one, then it will update the display and show the new image, but this is what happens:

if: C:tempscr.png does not exist you can drop a .png image into the window, it copys it and calls it tempscr.png then display the image in the window

If: C:tempscr.png DOES exist then when you drop another .png in the window, we know it picks up the new file location from the msgbox, but it wont replace the current png and im not sure why.

#include <GUIConstantsEx.au3>
#Include <Icons.au3>

dragandrop()

Func dragandrop() ;window for receiving drag and drop pictures.

$PNGlocation = "C:\tempscr.png"

    $MainWindow = GUICreate("Drag Photo Here",200,200,0,-1,-1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)

    $Pic1=GUICtrlCreatePic('', 10,30,180,160)

    GUICtrlSetState(-1,$GUI_DROPACCEPTED)
   
    GUISetState()
_SetImage($Pic1, $PNGlocation)

EndFunc

    while (1)
       
        $msg=Guigetmsg()
       
        switch $msg
           
        case $GUI_EVENT_CLOSE
            ExitLoop
           
        case $GUI_EVENT_DROPPED
            MsgBox(64,"",@GUI_DRAGFILE) ;Filepath for png to be imported
            $Copyresult=FileCopy(StringReplace(@GUI_DRAGFILE,@CRLF,""), $PNGlocation,1)
            MsgBox(64,"",$Copyresult) ;filecopy succesfull or fail?
            _SetImage($Pic1, $PNGlocation)
        EndSwitch
    Wend
Edited by cookiemonster

Share this post


Link to post
Share on other sites



Sorry I dont understand what you mean by doesnt work? 

That would set the png location, but i dont want to change the location, I want to copy the png to the location

Share this post


Link to post
Share on other sites

Still not been able to get it to copy if the file already exists, changed the code slight to this:

#include <GUIConstantsEx.au3>
#Include <Icons.au3>
Global $PNGlocation = "C:\tempscr.png"

    $MainWindow = GUICreate("Drag Photo Here",200,200,0,-1,-1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)
    $Pic1=GUICtrlCreatePic('', 10,30,180,160)
    GUICtrlSetState(-1,$GUI_DROPACCEPTED)
    GUISetState()
    _SetImage($Pic1, $PNGlocation)  
    

    while (1)
       
        $msg=Guigetmsg()
       
        switch $msg
           
        case $GUI_EVENT_CLOSE
            ExitLoop
           
        case $GUI_EVENT_DROPPED
            MsgBox(64,"",@GUI_DRAGFILE) ;Filepath for png to be imported
            $Copyresult=FileCopy(StringReplace(@GUI_DRAGFILE,@CRLF,""), $PNGlocation,1)
            MsgBox(64,"",$Copyresult & @CRLF & $PNGlocation & @CRLF & @GUI_DRAGFILE) ;filecopy succesfull or fail?
            _SetImage($Pic1, $PNGlocation)
        EndSwitch
    Wend

Share this post


Link to post
Share on other sites

Think ive got a bit of progress, its because the png is set to read only so it cant replace it if it already exists, anyone got an idea on how to force it even if its read only?

Share this post


Link to post
Share on other sites

Maybe by using this before the FileCopy

FileSetAttrib($PNGlocation, "-R")

?

Share this post


Link to post
Share on other sites

Yeh that would of done it but then I realised that the script when ran in full already does that, its because i was just running this one part, cheers

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