Jump to content

Drag & Drop Image


Recommended Posts

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
Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...

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