cookiemonster Posted February 5, 2014 Posted February 5, 2014 (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 February 5, 2014 by cookiemonster
mikell Posted February 5, 2014 Posted February 5, 2014 This doesn't work ? case $GUI_EVENT_DROPPED MsgBox(64,"",@GUI_DRAGFILE) ;Filepath for png to be imported $PNGlocation=StringReplace(@GUI_DRAGFILE,@CRLF,"") _SetImage($Pic1, $PNGlocation)
cookiemonster Posted February 5, 2014 Author Posted February 5, 2014 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
cookiemonster Posted February 5, 2014 Author Posted February 5, 2014 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
cookiemonster Posted February 5, 2014 Author Posted February 5, 2014 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?
mikell Posted February 5, 2014 Posted February 5, 2014 Maybe by using this before the FileCopy FileSetAttrib($PNGlocation, "-R") ?
cookiemonster Posted February 19, 2014 Author Posted February 19, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now