Jump to content

how to detect which TextBox received the dropped file?


Recommended Posts

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

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

Link to comment
Share on other sites

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

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