Jump to content
Sign in to follow this  
hamohd70

how to detect which TextBox received the dropped file?

Recommended Posts

hamohd70

I have a form with 2 textboxes and both accept drag and drop of files.

how can I detect where the file was dropped? is it on text 1 or text 2?

based on this I will write my action for each case.

 

Thanks

Share this post


Link to post
Share on other sites
computergroove

Each text box will be labeled something different in autoit. You can write a loop that listens for data coming from each separate box. Do you have any code yet? Can you share it?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
hamohd70

here is my code

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

$hGUI = GUICreate("Dropped Files", 500, 400, Default, Default, Default, $WS_EX_ACCEPTFILES)

$hEdit = GUICtrlCreateEdit("", 10, 10, 480, 180)
GUICtrlSetState($hEdit, $GUI_DROPACCEPTED)
$hEdit_Handle = GUICtrlGetHandle($hEdit)

$hEdit2 = GUICtrlCreateEdit("", 10, 210, 480, 180)
GUICtrlSetState($hEdit2, $GUI_DROPACCEPTED)
$hEdit_Handle2 = GUICtrlGetHandle($hEdit2)

GUISetState(@SW_SHOW)

Dim $EditControl

While 1
    $EditControl=GUIGetMsg(1)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $GUI_EVENT_DROPPED
            drop($EditControl)
    EndSwitch
WEnd

Func drop($EditControlArray)
    Switch $EditControlArray[0]
        Case $hEdit2
                Local $sLine, $iLine, $m3u8AddedFromFile=False
                $hFile = FileOpen(@GUI_DragFile)
                If $hFile = -1 Then
                    MsgBox(0,'ERROR','Unable to open file for reading.')
                        Exit 1
                EndIf

                While 1
                   $iLine += 1
                   $sLine = FileReadLine($hFile)
                   If @error = -1 Then ExitLoop

                   If StringInStr($sLine, "http://") Then
                      GUICtrlSetData($hEdit2, $sLine)
                      $m3u8AddedFromFile=True
                      ExitLoop
                   EndIf
                WEnd
            if $m3u8AddedFromFile=False then GUICtrlSetData($hEdit2, @GUI_DragFile)
            FileClose($hFile)
        Case $hEdit
            GUICtrlSetData($hEdit, @GUI_DragFile)
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites
UEZ

Try this:

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

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Dropped Files", 500, 400, Default, Default, Default, BitOR($WS_EX_TOPMOST, $WS_EX_ACCEPTFILES))

$hEdit = GUICtrlCreateEdit("", 10, 10, 480, 180)
GUICtrlSetState($hEdit, $GUI_DROPACCEPTED)
$hEdit_Handle = GUICtrlGetHandle($hEdit)

$hEdit2 = GUICtrlCreateEdit("", 10, 210, 480, 180)
GUICtrlSetState($hEdit2, $GUI_DROPACCEPTED)
$hEdit_Handle2 = GUICtrlGetHandle($hEdit2)

GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_DROPPED, "drop")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Dim $EditControl

While Sleep(1000)
WEnd

Func _Exit()
        GUIDelete()
        Exit
EndFunc

Func drop()
    Switch @GUI_DropId
        Case $hEdit2
                Local $sLine, $iLine, $m3u8AddedFromFile=False
                $hFile = FileOpen(@GUI_DragFile)
                If $hFile = -1 Then
                    MsgBox(0,'ERROR','Unable to open file for reading.')
                        Exit 1
                EndIf

                While 1
                   $iLine += 1
                   $sLine = FileReadLine($hFile)
                   If @error = -1 Then ExitLoop

                   If StringInStr($sLine, "http://") Then
                      GUICtrlSetData($hEdit2, $sLine)
                      $m3u8AddedFromFile=True
                      ExitLoop
                   EndIf
                WEnd
            if $m3u8AddedFromFile=False then GUICtrlSetData($hEdit2, @GUI_DragFile)
            FileClose($hFile)
        Case $hEdit
            GUICtrlSetData($hEdit, @GUI_DragFile)
    EndSwitch
EndFunc

Br,

UEZ


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
hamohd70

Try this:

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

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Dropped Files", 500, 400, Default, Default, Default, BitOR($WS_EX_TOPMOST, $WS_EX_ACCEPTFILES))

$hEdit = GUICtrlCreateEdit("", 10, 10, 480, 180)
GUICtrlSetState($hEdit, $GUI_DROPACCEPTED)
$hEdit_Handle = GUICtrlGetHandle($hEdit)

$hEdit2 = GUICtrlCreateEdit("", 10, 210, 480, 180)
GUICtrlSetState($hEdit2, $GUI_DROPACCEPTED)
$hEdit_Handle2 = GUICtrlGetHandle($hEdit2)

GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_DROPPED, "drop")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Dim $EditControl

While Sleep(1000)
WEnd

Func _Exit()
        GUIDelete()
        Exit
EndFunc

Func drop()
    Switch @GUI_DropId
        Case $hEdit2
                Local $sLine, $iLine, $m3u8AddedFromFile=False
                $hFile = FileOpen(@GUI_DragFile)
                If $hFile = -1 Then
                    MsgBox(0,'ERROR','Unable to open file for reading.')
                        Exit 1
                EndIf

                While 1
                   $iLine += 1
                   $sLine = FileReadLine($hFile)
                   If @error = -1 Then ExitLoop

                   If StringInStr($sLine, "http://") Then
                      GUICtrlSetData($hEdit2, $sLine)
                      $m3u8AddedFromFile=True
                      ExitLoop
                   EndIf
                WEnd
            if $m3u8AddedFromFile=False then GUICtrlSetData($hEdit2, @GUI_DragFile)
            FileClose($hFile)
        Case $hEdit
            GUICtrlSetData($hEdit, @GUI_DragFile)
    EndSwitch
EndFunc

Br,

UEZ

 

Working. Thanks alot

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
Sign in to follow this  

×