myspacee Posted May 11, 2015 Share Posted May 11, 2015 Hello,try to create a GUI with 2 drag&drop area. Start from an example find in forum:expandcollapse popup#include <APIConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> #include <StaticConstants.au3> #include <File.au3> ; For Pathsplit #include <WindowsConstants.au3> ; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop() Global $g_aDropFiles[0] Local $hGUI = GUICreate('', 300, @DesktopHeight-100, @DesktopWidth-330, 30, -1, $WS_EX_ACCEPTFILES) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" ; Create a label that is transparent which will accept 'drop' events. Local $annuncio_FOTO = GUICtrlCreateButton("trascina FOTO" & @CRLF, 0, @DesktopHeight-450, 300, 150) GUICtrlSetBkColor(-1, 0xE0FFFF) GUICtrlSetState($annuncio_FOTO, $GUI_DROPACCEPTED) Local $annuncio_AZIONI = GUICtrlCreateButton("AZIONI" & @CRLF, 0, @DesktopHeight-250, 300, 150) GUICtrlSetBkColor(-1, 0xE0FFFF) ;~ GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState($annuncio_AZIONI, $GUI_DROPACCEPTED) GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES') GUISetState(@SW_SHOW, $hGUI) Local $aDropped = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED $aDropped = GetDropFiles() ; This always returns a valid array regardless of an error If IsValidDrop() Then _ArraySort($aDropped); Sort the array so the first file is at the top _ArrayDisplay($aDropped) ; <<<<<<<<<< error checking $FirstFile = $aDropped[1]; Select only the first file for the name $FileSplit = _PathSplit($FirstFile,$sDrive, $sDir, $sFilename, $sExtension) ; split the name from the path $sPath = $sDrive & $sDir ConsoleWrite('Path = ' & $sPath & @CRLF) ConsoleWrite('Drive = ' & $sDrive & @CRLF & 'Dir = ' & $sDir & @CRLF & 'Filename = ' & $sFilename & @CRLF & 'Extension = ' & $sExtension & @CRLF) ; <<<<<<<<<< error checking $sExtension = StringLower($sExtension) ;---------------------------------------- If $sExtension = '.doc' Or $sExtension = '.docx' Then Local $FindFiles = _FileListToArrayRec( $sPath, '*' & $sFilename & $sExtension, 1, 0) _ArrayDisplay($FindFiles, ".Par Files") If IsArray($FindFiles) Then For $i = 1 To $FindFiles[0] FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9) Sleep(100) Next EndIf ;~ _Repair() ElseIf $sExtension = '.rar' Then Local $FindFiles = _FileListToArrayRec( $sPath, '*' & StringTrimRight($sFilename, 2) & '*', 1, 0) _ArrayDisplay($FindFiles, ".Rar Files") If IsArray($FindFiles) Then For $i = 1 To $FindFiles[0] FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9) Sleep(100) Next EndIf ;~ straight to extract ElseIf $sExtension = '.zip' Or $sExtension = '.7z' Then Local $FindFiles = _FileListToArrayRec( $sPath, '*' & StringTrimRight($sFilename, 2) & '*', 1, 0) _ArrayDisplay($FindFiles, ".Zip/7z Files") If IsArray($FindFiles) Then For $i = 1 To $FindFiles[0] FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9) Sleep(100) Next EndIf ;~ straight to extract Else MsgBox(64, 'File Error', 'Unknown File Type') EndIf EndIf EndSwitch WEnd GUIDelete($hGUI) ; Get the dropped list of files Func GetDropFiles() Return $g_aDropFiles EndFunc ;==>GetDropFiles ; Use to determine if the drop was valid Func IsValidDrop() Return UBound($g_aDropFiles) > 0 EndFunc ;==>IsValidDrop Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $lParam If $iMsg = $WM_DROPFILES Then $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam) If Not UBound($g_aDropFiles) Then Local Const $aError[0] ; Empty array $g_aDropFiles = $aError ; Set with the empty array EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_DROPFILESTry different ways without luck. Please, can correct code for me ? thank you,m. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted May 11, 2015 Share Posted May 11, 2015 (edited) Edit: nvm I thought it was because your using buttons instead of an input/edit control but apparently it does work with buttons, but it also interfaces differently. Edited May 11, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
kylomas Posted May 11, 2015 Share Posted May 11, 2015 myspacee,Please describe what you expect your code to do or what the specific problem is. The code, as is, runs for me.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 Link to comment Share on other sites More sharing options...
myspacee Posted May 11, 2015 Author Share Posted May 11, 2015 (edited) Thank you for reply,two ares must do 2 different things, re-post for show waht i need:expandcollapse popup#include <APIConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> #include <StaticConstants.au3> #include <File.au3> ; For Pathsplit #include <WindowsConstants.au3> ; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop() Global $g_aDropFiles[0] Local $hGUI = GUICreate('', 300, @DesktopHeight-100, @DesktopWidth-330, 30, -1, $WS_EX_ACCEPTFILES) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" ; Create a label that is transparent which will accept 'drop' events. Local $annuncio_FOTO = GUICtrlCreateButton("AAA" & @CRLF, 0, @DesktopHeight-450, 300, 150) GUICtrlSetBkColor(-1, 0xE0FFFF) GUICtrlSetState($annuncio_FOTO, $GUI_DROPACCEPTED) Local $annuncio_AZIONI = GUICtrlCreateButton("BBB" & @CRLF, 0, @DesktopHeight-250, 300, 150) GUICtrlSetBkColor(-1, 0xE0FFFF) ;~ GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState($annuncio_AZIONI, $GUI_DROPACCEPTED) GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES') GUISetState(@SW_SHOW, $hGUI) Local $aDropped = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED $aDropped = GetDropFiles() ; This always returns a valid array regardless of an error If IsValidDrop() Then _ArraySort($aDropped); Sort the array so the first file is at the top _ArrayDisplay($aDropped) ; <<<<<<<<<< error checking $FirstFile = $aDropped[1]; Select only the first file for the name $FileSplit = _PathSplit($FirstFile,$sDrive, $sDir, $sFilename, $sExtension) ; split the name from the path $sPath = $sDrive & $sDir ConsoleWrite('Path = ' & $sPath & @CRLF) ConsoleWrite('Drive = ' & $sDrive & @CRLF & 'Dir = ' & $sDir & @CRLF & 'Filename = ' & $sFilename & @CRLF & 'Extension = ' & $sExtension & @CRLF) ; <<<<<<<<<< error checking If "YOU DROP FILE ON BUTTON AAA" then Else ;you drop on button BBB EndIf EndIf EndSwitch WEnd GUIDelete($hGUI) ; Get the dropped list of files Func GetDropFiles() Return $g_aDropFiles EndFunc ;==>GetDropFiles ; Use to determine if the drop was valid Func IsValidDrop() Return UBound($g_aDropFiles) > 0 EndFunc ;==>IsValidDrop Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $lParam If $iMsg = $WM_DROPFILES Then $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam) If Not UBound($g_aDropFiles) Then Local Const $aError[0] ; Empty array $g_aDropFiles = $aError ; Set with the empty array EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_DROPFILESI don't know how discern from drag on button 'AAA' and other.m. Edited May 11, 2015 by myspacee Link to comment Share on other sites More sharing options...
UEZ Posted May 11, 2015 Share Posted May 11, 2015 Check out @GUI_DropId Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
myspacee Posted May 11, 2015 Author Share Posted May 11, 2015 (edited) snip Edited May 11, 2015 by myspacee double post afert site down Link to comment Share on other sites More sharing options...
myspacee Posted May 11, 2015 Author Share Posted May 11, 2015 (edited) Thank you UEZ for suggestion,in in fact, GUI_DropId, is why i specify name in control :GUICtrlSetState($annuncio_FOTO, $GUI_DROPACCEPTED)but with my script GUI_DropId return an error when called; start thinking bad buttons use for Drag&drop area is reason... Edited May 11, 2015 by myspacee double post afert site down Link to comment Share on other sites More sharing options...
kylomas Posted May 11, 2015 Share Posted May 11, 2015 myspacee,You can test @GUI_DROPID (if @GUI_DROPID = ...) for which control received the drop, probably somewhere after $GUI_EVENT_DROPPED.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 Link to comment Share on other sites More sharing options...
guinness Posted May 12, 2015 Share Posted May 12, 2015 Oh sweet! I asked a similar question years ago. Let me look at your problem and update my drop files idea. I should come up with a better wrapper that I can post in the examples section. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
myspacee Posted May 12, 2015 Author Share Posted May 12, 2015 Hello,thank you for interest. This can solve a job question. thank you again Link to comment Share on other sites More sharing options...
guinness Posted May 12, 2015 Share Posted May 12, 2015 Well it was this >> https://www.autoitscript.com/forum/topic/111440-solved-_guictrllistview_create-and-wm_dropfiles/ but I actually can't understand what is wrong with your code. Maybe strip it back to something simple, as right now you have to make sure a directory contains a zip file etc. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
myspacee Posted May 12, 2015 Author Share Posted May 12, 2015 Hello,change approach :expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> ;~ #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <Array.au3> OnAutoItExitRegister('OnAutoItExit') ; Create GUI Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 300, @DesktopHeight-100, @DesktopWidth-330, 30) Local $idCheck = GUICtrlCreateCheckbox('Enable Drag && Drop', 10, 10, 120, 19) Local $idLabel = GUICtrlCreateLabel('', 0, @DesktopHeight-450, 300, 150) Global $g_hLabel = GUICtrlGetHandle($idLabel) GUICtrlSetBkColor(-1, 0xD3D8EF) Local $idLabel_B = GUICtrlCreateLabel('', 0, @DesktopHeight-270, 300, 150) Global $g_hLabel_B = GUICtrlGetHandle($idLabel_B) GUICtrlSetBkColor(-1, 0x123456) ;GUICtrlCreateLabel('Drop here', 175, 193, 50, 14) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Allow WM_DROPFILES to be received from lower privileged processes (Windows Vista or later) #cs If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($g_hLabel, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW) _WinAPI_ChangeWindowMessageFilterEx($g_hLabel, $WM_DROPFILES, $MSGFLT_ALLOW) EndIf #ce ; Register label window proc Global $g_hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') Global $g_pDll = DllCallbackGetPtr($g_hDll) Global $g_hProc = _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $g_pDll) Global $g_hProc_B = _WinAPI_SetWindowLong($g_hLabel_B, $GWL_WNDPROC, $g_pDll) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCheck _WinAPI_DragAcceptFiles($g_hLabel, GUICtrlRead($idCheck) = $GUI_CHECKED) _WinAPI_DragAcceptFiles($g_hLabel_B, GUICtrlRead($idCheck) = $GUI_CHECKED) EndSwitch WEnd Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_DROPFILES Local $sFileList = _WinAPI_DragQueryFileEx($wParam) If Not @error Then ConsoleWrite('--------------------------------------------------' & @CRLF) For $i = 1 To $sFileList[0] Local $sClassNN = _ControlGetClassnameNN($hWnd) ;~ MsgBox(4096, "", $sClassNN) ConsoleWrite($sFileList[$i] & @CRLF) ConsoleWrite($sClassNN & " - " & $hWnd & " - " & $iMsg & " - " & $wParam & " - " & $lParam & @CRLF) Next EndIf _WinAPI_DragFinish($wParam) Return 0 EndSwitch Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Func OnAutoItExit() _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $g_hProc) _WinAPI_SetWindowLong($g_hLabel_B, $GWL_WNDPROC, $g_hProc) DllCallbackFree($g_hDll) EndFunc ;==>OnAutoItExit Func _ControlGetClassnameNN($hControl) If Not IsHWnd($hControl) Then Return SetError(1, 0, "") Local Const $hParent = _WinAPI_GetParent($hControl) If Not $hParent Then Return SetError(2, 0, "") Local Const $sList = WinGetClassList($hParent) Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2) _ArraySort($aList) Local $nInstance, $sLastClass, $sComposite For $i = 0 To UBound($aList) - 1 If $sLastClass <> $aList[$i] Then $sLastClass = $aList[$i] $nInstance = 1 EndIf $sComposite = $sLastClass & $nInstance If ControlGetHandle($hParent, "", $sComposite) = $hControl Then Return $sComposite $nInstance += 1 Next Return SetError(3, 0, "") EndFunc ; _ControlGetClassnameNN()and now can monitor more than 2 defined areas. Not too elegant i know but works. Can anyone correct weak syntax ?thank you for all your time,m. Link to comment Share on other sites More sharing options...
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