Jump to content

[Solved] Drag & drop help


Recommended Posts

Hi.

Im trying to make a gui that will let me drop multiple files into its different areas, & then it consolewrites all dropped filepaths.

I searched around & none of the samples I found works. I just get load of errors.

Also tried the help file & found one working example, but it does not work the way I want it. It just lets me drop 1 file into txt area. But my dropped areas must be bigger & I want to drop multiple files.

This is what I got so far.

#include <ButtonConstants.au3>
#include <ListBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)        ;0=disabled, 1=OnEvent mode enabled

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Blacklister 1.0", 493, 125, 193, 115, -1, 0x00000018)

;## Draop Area 1

    $cg_btn = GUICtrlCreateButton("CG", 115, 16, 91, 89, 0)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetOnEvent($GUI_EVENT_DROPPED, "_manga")

;## Draop Area 2
$List1 = GUICtrlCreateList("", 9, 18, 91, 89)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetOnEvent($GUI_EVENT_DROPPED, "_cg")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(10)
WEnd

Func _cg()
    ConsoleWrite("CG_ID: "&@GUI_DRAGID & " File: "&@GUI_DRAGFILE &" Drop: "&@GUI_DROPID&@CRLF)
EndFunc

Func _manga()
    ConsoleWrite("MANGA_ID: "&@GUI_DRAGID & " File: "&@GUI_DRAGFILE &" Drop: "&@GUI_DROPID&@CRLF)
EndFunc

Func _Exit()
    Exit
EndFunc
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Search the Forum for WM_DROPFILES, this should get you started.

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

Search the Forum for WM_DROPFILES, this should get you started.

thanx, I got most of this to work, there is only 1 little problem, How do I know into which area did I drop my files? For example if I dropped my files into button 1 I want to call _Functon1, if into button 2 then call _Function2.

So is there a way to tell into which button I dropped my files into?

Working sample with 1 little problem.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=
    global $Form1 = GUICreate("Form1", 325, 243, 192, 124)

    Global $hDropGUI = GUICreate("DropGUI", 97, 41, 120, 88, BitOR($WS_CHILD, $WS_VISIBLE), BitOR($WS_EX_ACCEPTFILES, $WS_EX_CONTROLPARENT), $Form1)
    global $Button1 = GUICtrlCreateButton("Button1", 0, 0, 97, 41)
    GUICtrlSetState($Button1, $GUI_DROPACCEPTED);
    GUISwitch($Form1)

    Global $hDropGUI2 = GUICreate("DropGUI2", 197, 41, 120, 88, BitOR($WS_CHILD, $WS_VISIBLE), BitOR($WS_EX_ACCEPTFILES, $WS_EX_CONTROLPARENT), $Form1)
    global $Button2 = GUICtrlCreateButton("Button1", 100, 0, 97, 41)
    GUICtrlSetState($Button2, $GUI_DROPACCEPTED);
    GUISwitch($Form1)


    GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose');

    GUISetState(@SW_SHOW)

    #EndRegion ### END Koda GUI section ###

    Const $WM_DROPFILES = 0x233;
    GUIRegisterMsg($WM_DROPFILES, "On_WM_DROPFILES")

While 1
    Sleep(100)
WEnd

Func _onClose()
    GUIDelete()
    Exit
EndFunc

Func _evDroppedFiles(ByRef $dFiles)
    local $x, $files;
    For $x = 0 To UBound($dFiles)-1
        $files &= $dFiles[$x] & @CRLF
    Next
;~     MsgBox(64, 'func1', StringTrimRight($files, 2));
        ConsoleWrite(StringTrimRight($files, 2) & @CRLF)
EndFunc

Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam)
    Local $tDrop, $i, $aRet, $iCount;
    ;get file count
    $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", -1, "ptr", 0, "uint", 0 )
    $iCount = $aRet[0]
    ;get file paths
    local $aDraggedFiles[$iCount];
    For $i = 0 To $iCount-1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", 0, "uint", 0)
        Local $tDrop = DllStructCreate("wchar[" & $aRet[0]+1 & "]")
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "uint", $aRet[0]+1)
        $aDraggedFiles[$i] = DllStructGetData($tDrop, 1);
    Next
    ;finalize
    DllCall("shell32.dll", "int", "DragFinish", "ptr", $wParam)
    Return _evDroppedFiles($aDraggedFiles);
EndFunc
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Have a look at this post >>

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

Have a look at this post >>

Oh awsome, I got it to work, thanx, this should really be under drag & drop in the help file.

in any case, hire is working code if someone will need it:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global Const $WM_DROPFILES = 0x0233
Global $hGUI, $hLV_1, $hLV_2, $cg_btn

#Region ### START Koda GUI section ### 
$hGUI = GUICreate("Blacklister 1.0", 493, 125, 193, 115, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
;~ ConsoleWrite("$hGUI      = " & $hGUI & @LF)

$manga_btn = GUICtrlCreateButton("Manga", 10, 16, 91, 89)
$hLV_1 = ControlGetHandle($hGUI, "", $manga_btn)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
;~ ConsoleWrite("$manga_btn = " & $hLV_1 & @LF)

$cg_btn = GUICtrlCreateButton("CG", 115, 16, 91, 89)
$hLV_2 = ControlGetHandle($hGUI, "", $cg_btn)
;~ ConsoleWrite("$cg_btn        = " & $hLV_2 & @LF)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
;~     ConsoleWrite("WM_DROPFILES_FUNC:  $hWnd = " & $hWnd & @LF)
    Switch $hWnd
        Case $hGUI ; Our GUI
            Local Const $tagPOINT = "int X;int Y"
            Local $tPOINT = DllStructCreate($tagPOINT), $iX, $iY
            Local $aRET, $hCtrl, $nSize, $tFileName

            ; Get X/Y coord dropped to
            $aRET = DllCall("shell32.dll", "int", "DragQueryPoint", "hwnd", $wParam, "ptr", DllStructGetPtr($tPOINT))
            $iX = DllStructGetData($tPOINT, "X")
            $iY = DllStructGetData($tPOINT, "Y")
            $hCtrl = _GetCtrlHandleFromPoint($iX, $iY)
;~             ConsoleWrite("$iX = " & $iX & "; $iY = " & $iY & "; $hCtrl = " & $hCtrl & @LF)

            Switch $hCtrl
                Case $hLV_1, $hLV_2
                    ; Get count of files dropped
                    $aRET = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
                    For $i = 0 To $aRET[0] - 1
                        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
                        $nSize = $nSize[0] + 1
                        $tFileName = DllStructCreate("char[" & $nSize & "]")
                        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($tFileName), "int", $nSize)

                        ;## If not dropped into gui ak. dropped somewhere else
                            If $hCtrl <> $hGUI Then
                                ConsoleWrite($hCtrl & ' ' & DllStructGetData($tFileName, 1) & @CRLF)
                            EndIf

                        $tFileName = 0
                    Next
                    Return 0 ; End processing only for our LVs
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_DROPFILES_FUNC

Func _GetCtrlHandleFromPoint($iX, $iY)
    $aLV_Pos = ControlGetPos($hGUI, "", $hLV_1)
    If ($iX >= $aLV_Pos[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
        Return $hLV_1
    Else
        $aLV_Pos = ControlGetPos($hGUI, "", $hLV_2)
        If ($iX >= $aLV_Pos[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
            Return $hLV_2
        Else
            Return 0
        EndIf
    EndIf
EndFunc   ;==>_GetCtrlHandleFromPoint
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
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...