Jump to content
Sign in to follow this  

How to open a file by dragging it over a gui

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.

Share this post

Link to post
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)


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

_WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $hProc)

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]))
            Return 0
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc


Edited by Yashied

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.