set open file (drag-and-drop, hidden open dialog)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

set open file (drag-and-drop, hidden open dialog)

20 Jul 2017, 20:09

In many programs I can set the open file by using this technique (sending the message to the main window or to a control):

Code: Select all

q::
vPath = %A_Desktop%\MyFile.ext
PostMessage, 0x233, % JEE_DropCreate(vPath), 0,, A ;WM_DROPFILES := 0x233
return

;get 'JEE_DropCreate' from:
;notepad get/set path (get/set text file path) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=30050
Programs it works with:
- Notepad/WordPad/MS Paint (e.g. Windows XP and 7)
- Media Player Classic
- Excel/Word (tested on MS Office 2007) (but it opens the file in a new window, note: you can use COM)
- Notepad2, Resource Hacker, WinDjView, WinMerge

Programs it doesn't work with:
- Adobe Reader (but then, it appears that you can't *manually* drag-and-drop a file onto Adobe Reader either)
- Internet Explorer (you can use COM, note: manual drag-and-drop to IE does work)
- Explorer (you can use COM)
- Google Chrome, LibreOffice Writer/LibreOffice Calc, Mozilla Firefox

I found one example where a manual drag-and-drop *does* work, but where the technique above *doesn't* work:
Open selected file in SPEK - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=34754

So I was wondering if people had any other ideas re. drag-and-drop, or perhaps to invoke the Open dialog, but somehow keep it hidden, and open the file that way. (Btw one hack that I did consider at one point in the past, was to overlay the Open dialog, with a screenshot of the window, while the dialog was open.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: set open file (drag-and-drop, hidden open dialog)

21 Jul 2017, 12:43

This may be interesting, an object approach is mentioned, in case it looks easy to anyone to convert it into AHK. I might have a go myself when I get the chance, although I'm not so familiar with object interfaces. Cheers.

Sending WM_DROPFILES with C++ and WinAPI to third-party application - Stack Overflow
https://stackoverflow.com/questions/22271857/sending-wm-dropfiles-with-c-and-winapi-to-third-party-application

[EDIT:] I managed to create a script that programmatically drags and drops to Spek, using IDropTarget:
drag-and-drop programmatically by using OleDropTargetInterface - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=56720
Last edited by jeeswg on 13 Oct 2019, 02:14, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: set open file (drag-and-drop, hidden open dialog)

21 Jul 2017, 22:58

Code: Select all

q:: ;check if a window/control accepts files (drag-and-drop)
WinGet, hWnd, ID, A
vOutput := ""

WinGetClass, vWinClass, % "ahk_id " hWnd
WinGet, vWinExStyle, ExStyle, % "ahk_id " hWnd
vDoesAccept := (vWinExStyle & 0x10) >> 4
vOutput .= vDoesAccept "`t" vWinClass "`r`n"

WinGet, vCtlList, ControlList, % "ahk_id " hWnd
Loop, Parse, vCtlList, `n
{
	vCtlClassNN := A_LoopField
	ControlGet, hCtl, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd

	;WS_EX_ACCEPTFILES := 0x10
	WinGet, vWinExStyle, ExStyle, % "ahk_id " hCtl
	vDoesAccept := (vWinExStyle & 0x10) >> 4
	vOutput .= vDoesAccept "`t" vCtlClassNN "`r`n"
}

Clipboard := vOutput
MsgBox, % vOutput
return

w:: ;change a window have the WS_EX_ACCEPTFILES style
;however, this does not necessarily make it accept files
;WS_EX_ACCEPTFILES := 0x10
WinGet, vWinExStyle, ExStyle, A
MsgBox, % (vWinExStyle & 0x10) >> 4
return
[1500th post]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer, gongnl and 274 guests