Gui Edit control accept file paste? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
william_ahk
Posts: 510
Joined: 03 Dec 2018, 20:02

Gui Edit control accept file paste?

Post by william_ahk » 21 Apr 2024, 21:05

How can we make the Edit control to recognize the CF_HDROP format as a string, so that when we paste a file into it the filepath would be taken in? I don't want to register hotkeys to achieve this like ^v::MyGui.FocusedCtrl.Value := A_Clipboard

teadrinker
Posts: 4408
Joined: 29 Mar 2015, 09:41
Contact:

Re: Gui Edit control accept file paste?  Topic is solved

Post by teadrinker » 22 Apr 2024, 06:17

Code: Select all

#Requires AutoHotkey v2

wnd := Gui()
fileAcceptor := wnd.AddEdit('w400 h200')
OnMessage(WM_CHAR := 0x102, OnPaste)
wnd.Show()

OnPaste(wp, *) {
    if !(wp = 22 && fileAcceptor.Focused) {
        return
    }
    DllCall('OpenClipboard', 'Ptr', A_ScriptHwnd)
    if hData := DllCall('GetClipboardData', 'UInt', CF_HDROP := 15, 'Ptr') {
        pDROPFILES := DllCall('GlobalLock', 'Ptr', hData, 'Ptr')
        addr := pDROPFILES + NumGet(pDROPFILES, 'UInt')
        while (filePath := StrGet(addr)) != '' {
            filePaths .= filePath . '`r`n'
            addr += StrPut(filePath)
        }
        DllCall('GlobalUnlock', 'Ptr', hData)
        EditPaste filePaths, fileAcceptor
    }
    DllCall('CloseClipboard')
}
Like this?

william_ahk
Posts: 510
Joined: 03 Dec 2018, 20:02

Re: Gui Edit control accept file paste?

Post by william_ahk » 22 Apr 2024, 06:36

Yes that's just what I need :thumbup:
This would cover most cases. But just a thought - is there any wizardry we can apply to Context Menu - Paste (or Shift+Ins) without modifying the clipboard?

teadrinker
Posts: 4408
Joined: 29 Mar 2015, 09:41
Contact:

Re: Gui Edit control accept file paste?

Post by teadrinker » 22 Apr 2024, 09:36

If there is a file on the clipboard, the Paste menu item is disabled, at least for me.

william_ahk
Posts: 510
Joined: 03 Dec 2018, 20:02

Re: Gui Edit control accept file paste?

Post by william_ahk » 22 Apr 2024, 19:30

Yeah I guess I'll have to make a custom context menu in that case. But anyway, this is sufficient to me :D

Post Reply

Return to “Ask for Help (v2)”