Jump to content

How to open a file by dragging it over a gui


Hawkwing
 Share

Recommended Posts

I think it's possible, but I've no idea how to do it. It's a text file I'm opening into an edit control if it makes any difference.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

Global Const $WM_DROPFILES = 0x0233

Global $hForm, $Msg, $Check, $Edit, $hEdit, $hDll, $pDll, $hProc

; Create GUI
$hForm = GUICreate('MyGUI', 400, 400)
$Check = GUICtrlCreateCheckbox('Enable Drag && Drop', 20, 370, 120, 19)
$Edit = GUICtrlCreateEdit('', 20, 20, 360, 340)
$hEdit = GUICtrlGetHandle($Edit)

; Register window proc
$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $pDll)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Check
            _WinAPI_DragAcceptFiles($hEdit, GUICtrlRead($Check) = $GUI_CHECKED)
    EndSwitch
WEnd

_WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $hProc)
DllCallbackFree($hDll)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_DROPFILES

            Local $FileList = _WinAPI_DragQueryFileEx($wParam)

            If (Not @error) And ($FileList[0] = 1) Then
                GUICtrlSetData($Edit, FileRead($FileList[1]))
            EndIf
            _WinAPI_DragFinish($wParam)
            Return 0
    EndSwitch
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

WinAPIEx.au3

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