; LinkExplorerPathToFileDialog.ahk v0.02 WIP by koomi & Winkie
; *** WARNING: Alpha code! Use at your own risk! ***
; Makes a file dialog instantly jump to the folder of any Explorer Window you click
; Idea stolen from Direct Folders' "QuickSwitch" feature.
;
; How to use:
; 1) Open a file dialog (Open/Save, also works with 7-Zip Extract and so forth)
; 2) Switch to an open Windows Explorer window
; 3) The Open/Save dialog will change to same path as the Explorer window
; *) Autohotkey_L is recommended if your system has non-Western foldernames
;
; NEEDS HELP WITH:
; User testing
; Windows Vista/7 compatibility
; Better sanity checking to make sure we're really dealing with a file dialog
; Maybe by matching the window title against a list of known good ones?
; Work with folder tree dialogs as well (like Direct Folders)
; .INI file to allow specifying custom class+control+title combinations
; Microsoft Office 2007/2010 compatibility
; Pretty icon and menu stuff like "Disable/Enable"
; Flash taskbar/caption of dialog parent when path is changed or something
#SingleInstance Force
#Persistent
SetBatchLines,-1
Gui +LastFound
shWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt
,shWnd
) MsgNum :
= DllCall( "RegisterWindowMessage", Str
,"SHELLHOOK" )OnMessage( MsgNum, "ShellMessage" )
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
; See http://www.autohotkey.com/forum/post-123323.html
ShellMessage( wParam,lParam )
{
; See http://msdn.microsoft.com/en-us/library/ms644989.aspx
If ( wParam
= 1 || wParam
= 4 ) ; HSHELL_WINDOWCREATED := 1 OR HSHELL_WINDOWACTIVATED := 4 {
WinGetClass, Class, ahk_id %lParam%
; Is this an Explorer window?
If (Class
= "CabinetWClass" OR Class
= "ExploreWClass") ; Might need adjustment for Vista/Win7 {
; Do we have a Open/Save control handle available?
{
; Get text from dialog now, user can edit it in the meantime
; If full path in title is not set, try to catch path from edit
If ExplorerTitle
Not Contains \
If ExplorerTitle Contains \
; if not, it's My Computer, Control Panel etc. {
If (LastCharacter
<> "\") {
; Change the path to the Explorer path
; Put the original filename back in the dialog edit control
}
; For cases like 7-Zip "Extract" dialog which contain pathnames, not filenames
}
; Back to where we started...
ControlHwnd =
DialogClass =
}
}
}
}
; See http://www.autohotkey.com/forum/topic35659.html
HookProc
( hWinEventHook
, Event
, hWnd, idObject
, idChild
, dwEventThread
, dwmsEventTime
){
If Event
; EVENT_SYSTEM_FOREGROUND = 0x3 {
; Windows and dialog boxes need time to "settle". See AHK manual
WinGetClass, DialogClass, ahk_id %hWnd%
; Is this a typical Open/Save dialog box?
If DialogClass Contains bosa_sdm
; Might need adjustment for Office 2007 or 2010 If ( DialogClass
= "#32770" || OfficeDialog
) {
; Get control handle of edit for use in ShellMessage()
EditClass = Edit1 ; Default
EditClass = RichEdit20W2 ; Might need adjustment for Office 2007 or 2010
ControlGet
, ControlHwnd
, Hwnd,, %EditClass%
, ahk_id
%hWnd%
}
}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
DllCall( "UnhookWinEvent", Uint
,hWinEventHook
) DllCall( "GlobalFree", UInt
,&HookProcAdr
) ; free up allocated memory for RegisterCallback }
HandleExit:
UnhookWinEvent()
ExitApp