Gui Edit control accept file paste? Topic is solved
-
- Posts: 510
- Joined: 03 Dec 2018, 20:02
Gui Edit control accept file paste?
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
-
- Posts: 4408
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Gui Edit control accept file paste? Topic is solved
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')
}
-
- Posts: 510
- Joined: 03 Dec 2018, 20:02
Re: Gui Edit control accept file paste?
Yes that's just what I need
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?
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?
-
- Posts: 4408
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Gui Edit control accept file paste?
If there is a file on the clipboard, the Paste menu item is disabled, at least for me.
-
- Posts: 510
- Joined: 03 Dec 2018, 20:02
Re: Gui Edit control accept file paste?
Yeah I guess I'll have to make a custom context menu in that case. But anyway, this is sufficient to me