Jump to content

Accepting dropped files - can the drop indicator only appear only over the specified item?


Recommended Posts

Hello, everyone - I hope everyone is doing well...

I am working on a project where it will accept drag & drop files (an mp3 encoder). Working great so far. However, I notice when you drag a file over the GUI, it has a plus symbol indicating you are able to drop it anywhere over the GUI. I would like that plus symbol to only appear over the intended input box. I think it's confusing to think you can drag & drop a file anywhere, but actually only be able to over the specified item.

Can this be accomplished? I haven't found any threads on this particular subject.

Thanks for any ideas!

Whittled down example code:

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

$Form2 = GUICreate("Form2", 565, 247, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$Input1 = GUICtrlCreateInput("", 32, 16, 505, 21)  ; <-- This is the only place I want the drop indicator to appear.
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$Tab1 = GUICtrlCreateTab(32, 48, 505, 185)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
            $gRead = GUICtrlRead($Input1)
            GUICtrlSetData($Input1, $gRead)
    EndSwitch
WEnd

 

Edited by abberration
Link to comment
Share on other sites

Try this :

#include <GUIConstants.au3>

$Form2 = GUICreate("Form2", 565, 247, -1, -1, -1, $WS_EX_WINDOWEDGE)
$Input1 = GUICtrlCreateInput("", 32, 16, 505, 21, -1, $WS_EX_ACCEPTFILES)  ; Now only here the drop sign appears
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $GUI_EVENT_DROPPED                 ; Not triggered, I think it should be considered as a bug
      ConsoleWrite (@GUI_DragFile & @CRLF)
    Case $Input1
      ConsoleWrite ("input1" & @CRLF)
  EndSwitch
WEnd

But no msg is triggered.  I would tend to consider it as a bug.  There must be a more complex solution that I cannot think at the moment. 

Link to comment
Share on other sites

Found a way, still I tend to believe it might be a bug. But anyway, I have found a way not too complicated :

#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Global $aFileList

$hGUI = GUICreate("Form2", 565, 247, -1, -1, -1, $WS_EX_WINDOWEDGE)
$Input1 = GUICtrlCreateInput("", 32, 16, 505, 121, -1, $WS_EX_ACCEPTFILES)  ; Now only here the drop sign appears
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $idDummy = GUICtrlCreateDummy()
GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $GUI_EVENT_DROPPED                 ; Not triggered, I think it should be considered as a bug
      ConsoleWrite(@GUI_DragFile & @CRLF)
    Case $Input1
      ConsoleWrite("input1" & @CRLF)
    Case $idDummy
      For $i = 1 To $aFileList[0]
        ConsoleWrite($aFileList[$i] & @CRLF)
      Next
      GUICtrlSetData ($Input1, _ArrayToString ($aFileList,"|",1))
  EndSwitch
WEnd

GUIDelete($hGUI)
DllCallbackFree($wProcHandle)

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
  Switch $hWnd
    Case GUICtrlGetHandle($Input1)
      Switch $Msg
        Case $WM_DROPFILES
          $aFileList = _WinAPI_DragQueryFileEx($wParam)
          If Not @error Then GUICtrlSendToDummy($idDummy)
          _WinAPI_DragFinish($wParam)
          Return 0
      EndSwitch
  EndSwitch

  Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>_WindowProc

Needs some cleanup but you will get the idea...

Edited by Nine
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...