Jump to content

[SOLVED] parse drag, drop files without guictrlread()


Xandy
 Share

Recommended Posts

With drag and drop files, I really need a way to parse the files dropped before they land on an input field.

Or I need away to clear the input field before the file drop takes place

For example if I only drop one file, I can set the input field to the @gui_dragfile

however if I drop 2 or more files, I have only learned that I can parse the input field for the separator char "|".

This works fine if the input I drop the files onto is empty,

But when I drop files onto a input with a value not equal to "" the file path is inserted into the input field whereever I released the mouse button

makeing it very hard to distingwish between the new path I want inserted into the input field and the old input data I want removed

I could add a check for $GUI_EVENT_PRIMARYUP then decide if the mouse is over a input field but I don't want to clear the field everytime the mouse is released over an input field, I only want to clear the field if I'm dropping files onto it. Is there a way to analize only the files dropped without reading the input field value? Or a way to clear the input field before the drop takes place? I have searched for days over months to find a solution to this issue, and I must not know the right way to search for this answer.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
$inputfieldmax= 10
$hgui= 0

if $hgui== 0 then
    $hgui = guicreate("Drag, drop file", 600, $inputfieldmax*30, 0, 0, -1, $WS_EX_ACCEPTFILES);
endif

;create input fields
dim $inputfield[$inputfieldmax]
for $i= 0 to $inputfieldmax-1
    GUICtrlCreateLabel($i, 5, 10+29*$i)
    $inputfield[$i] = GUICtrlCreateInput("", 25, 10+29*$i, 340, 21)
    GUICtrlSetState($inputfield[$i], $GUI_DROPACCEPTED)
next
GUISetState(@sw_show)

dim $function[$inputfieldmax];
$done= 0
while $done== 0
    $msg= GUIGetMsg()
    if $msg== $GUI_EVENT_DROPPED then 
        for $i=0 to $inputfieldmax-1
            $tempstring= GUICtrlRead($inputfield[$i])
            $filedrop= StringSplit($tempstring, "|")
            for $ii= 1 to $filedrop[0]
                if($filedrop[0]== 1 and $inputfield[$i+$ii-1]== @GUI_DropId) then 
                    $function[$ii-1]= @GUI_DragFile
                Else
                    $function[$ii-1]= $filedrop[$ii]
                endif
                GUICtrlSetData($inputfield[$i+$ii-1], $function[$ii-1])
            next
        next
    endif
    if $msg== $GUI_EVENT_CLOSE then $done= 1
WEnd

Guinness thank you for directing me to the solution to my problem.

I was reluctant to use GUIRegisterMsg() when I saw a similar autoit topic because the function reminded me of a callback function I had registered previously to capture scroll mouse wheel events:

$hFunc = DllCallbackRegister('_MouseProc', 'lresult', 'int;int;int')

the callback function caused right-click panning to become crazy fast, as in a slight movement of the mouse resulted in the cursor leaving the window.

So I decided that registering callbacks effected system speed behavior and removed the ability to capture scroll mouse wheel events. Because I don't really understand dll stuff or how everything works here in autoit, I was too reluctant to try the GUIRegisterMsg() example. Because you told me WM_DROPFILES was what I needed, I tried it. It works perfectly so far, and does not cause the pann glitch. Now comparing the DllCallbackRegister() and GUIRegisterMsg(), I will only suspect registering callbacks to heavy effect system performance.

Thanks again,

here is the code that allows me to overwrite the input field with drag drop files:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
$inputfieldmax= 10
$hgui= 0
Global Const $WM_DROPFILES = 0x233
Global $gaDropFiles[1]
GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")
if $hgui== 0 then
    $hgui = guicreate("Drag, drop file", 600, $inputfieldmax*30, 0, 0, -1, $WS_EX_ACCEPTFILES);
endif

;create input fields
dim $inputfield[$inputfieldmax]
for $i= 0 to $inputfieldmax-1
    GUICtrlCreateLabel($i, 5, 10+29*$i)
    $inputfield[$i] = GUICtrlCreateInput("", 25, 10+29*$i, 340, 21)
    GUICtrlSetState($inputfield[$i], $GUI_DROPACCEPTED)
next
GUISetState(@sw_show)

dim $function[$inputfieldmax];
$done= 0
while $done== 0
    $msg= GUIGetMsg()
    if $msg== $GUI_EVENT_DROPPED then 
        for $i= 0 to $inputfieldmax-1
            if $inputfield[$i]== @GUI_DropId Then
                $temp= $i
                ExitLoop
            endif
        next
        For $i= 0 To UBound($gaDropFiles) - 1
            if($temp+$i < $inputfieldmax) then 
                $function[$temp+$i]=$gaDropFiles[$i]
                GUICtrlSetData($inputfield[$temp+$i], $function[$temp+$i])
            endif
        next
    endif
    if $msg== $GUI_EVENT_CLOSE then $done= 1
WEnd
    
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) 
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i+1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc
Edited by songersoft
Link to comment
Share on other sites

With drag and drop files, I really need a way to parse the files dropped before they land on an input field.

Have you searched for WM_DROPFILES in the Forum?

Example 1:

Example 2:

Or a way to clear the input field before the drop takes place?

GUICtrlSetData() of course, but I really think WM_DROPFILES will help you! Edited by guinness

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...