Jump to content
myspacee

Two drag&drop areas on same GUI

Recommended Posts

myspacee

Hello,
try to create a GUI with 2 drag&drop area. Start from an example find in forum:

#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_DROPFILES

Try different ways without luck. Please, can correct code for me ?

 

thank you,
m.
 

Share this post


Link to post
Share on other sites
ViciousXUSMC

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 by ViciousXUSMC

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
myspacee

Thank you for reply,

two ares must do 2 different things, re-post for show waht i need:

#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_DROPFILES

I don't know how discern from drag on button 'AAA' and other.

m.

Edited by myspacee

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
myspacee

snip

Edited by myspacee
double post afert site down

Share this post


Link to post
Share on other sites
myspacee

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 by myspacee
double post afert site down

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
myspacee

Hello,

thank you for interest. This can solve a job question.

 

thank you again

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
myspacee

Hello,

change approach :

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

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.