DonationCoder.com Software > Post New Requests Here
IDEA: Insta-switch file dialog to any Explorer window's path (code included)
lanux128:
FlashFolder has this feature and apart from windows explorer, it also supports total commander. however FlashFolder has no support for windows 7 and isn't being actively developed.
Winkie:
If anyone would like to take a stab at any of the "NEEDS HELP WITH" or offer suggestions it would be greatly appreciated!-koomi (April 01, 2010, 08:25 PM)
--- End quote ---
Well, here is my input. (I've only been able to test it on a pc with WinXP and Office 2003.)
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?
Microsoft Office compatibility-koomi
--- End quote ---
IMHO, Class #32770 is the only "real" one. MS Office has different ones. I added a check for them. But that won't probably work with Office 2007 and later.
Work with folder tree dialogs as well (like Direct Folders)-koomi
--- End quote ---
Should be possible, but I don't how (yet?).
EDIT:
Code is in here: New Context Menu Item Puts Any Folder Into a Dialog Window. Also Vista is mentioned here.
Allow modification of the filename after the dialog first opens-koomi
--- End quote ---
I implemented that by moving the text-grabbing after switching to Explorer.
Your code only works if Window Explorer has the full file path in it's title. I don't have set that option, so I made it grab the path from the edit field instead. I also added a check which should prevent using Control Panel and My Computer etc.
Here is my updated code, please test it:
--- Code: AutoIt ---; 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#PersistentSetBatchLines,-1 Gui +LastFoundshWnd := 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, HandleExitReturn ; See http://www.autohotkey.com/forum/post-123323.htmlShellMessage( wParam,lParam ){ global ControlHwnd global DialogClass ; 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? If (ControlHwnd) { ; Get text from dialog now, user can edit it in the meantime ControlGetText, ControlText, , ahk_id %ControlHwnd% StringRight, LastCharacter, ControlText, 1 WinGetTitle, ExplorerTitle, ahk_id %lParam% ; If full path in title is not set, try to catch path from edit If ExplorerTitle Not Contains \ ControlGetText, ExplorerTitle, Edit1, A If ExplorerTitle Contains \ ; if not, it's My Computer, Control Panel etc. { If (LastCharacter <> "\") { ; Change the path to the Explorer path ControlSetText,, %ExplorerTitle%, ahk_id %ControlHwnd% ControlSend,, {Enter}, ahk_id %ControlHwnd% ; Put the original filename back in the dialog edit control ControlSetText,, %ControlText%, ahk_id %ControlHwnd% } ; For cases like 7-Zip "Extract" dialog which contain pathnames, not filenames Else ControlSetText,, %ExplorerTitle%\, ahk_id %ControlHwnd% } ; Back to where we started... WinActivate, ahk_class %DialogClass% ControlHwnd = DialogClass = } } }} ; See http://www.autohotkey.com/forum/topic35659.htmlHookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime ){ global ControlHwnd global DialogClass If Event ; EVENT_SYSTEM_FOREGROUND = 0x3 { ; Windows and dialog boxes need time to "settle". See AHK manual Sleep, 120 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 OfficeDialog := True If ( DialogClass = "#32770" || OfficeDialog ) { ; Get control handle of edit for use in ShellMessage() EditClass = Edit1 ; Default If OfficeDialog 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){ DllCall("CoInitialize", Uint, 0) return DllCall("SetWinEventHook" , Uint,eventMin , Uint,eventMax , Uint,hmodWinEventProc , Uint,lpfnWinEventProc , Uint,idProcess , Uint,idThread , Uint,dwFlags)} UnhookWinEvent(){ Global DllCall( "UnhookWinEvent", Uint,hWinEventHook ) DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback} HandleExit:UnhookWinEvent()ExitAppReturn
Greetz Winkie
Contro:
If anyone would like to take a stab at any of the "NEEDS HELP WITH" or offer suggestions it would be greatly appreciated!-koomi (April 01, 2010, 08:25 PM)
--- End quote ---
Well, here is my input. (I've only been able to test it on a pc with WinXP and Office 2003.)
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?
Microsoft Office compatibility-koomi
--- End quote ---
IMHO, Class #32770 is the only "real" one. MS Office has different ones. I added a check for them. But that won't probably work with Office 2007 and later.
Work with folder tree dialogs as well (like Direct Folders)-koomi
--- End quote ---
Should be possible, but I don't how (yet?).
EDIT:
Code is in here: New Context Menu Item Puts Any Folder Into a Dialog Window. Also Vista is mentioned here.
Allow modification of the filename after the dialog first opens-koomi
--- End quote ---
I implemented that by moving the text-grabbing after switching to Explorer.
Your code only works if Window Explorer has the full file path in it's title. I don't have set that option, so I made it grab the path from the edit field instead. I also added a check which should prevent using Control Panel and My Computer etc.
Here is my updated code, please test it:
--- Code: AutoIt ---; 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#PersistentSetBatchLines,-1 Gui +LastFoundshWnd := 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, HandleExitReturn ; See http://www.autohotkey.com/forum/post-123323.htmlShellMessage( wParam,lParam ){ global ControlHwnd global DialogClass ; 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? If (ControlHwnd) { ; Get text from dialog now, user can edit it in the meantime ControlGetText, ControlText, , ahk_id %ControlHwnd% StringRight, LastCharacter, ControlText, 1 WinGetTitle, ExplorerTitle, ahk_id %lParam% ; If full path in title is not set, try to catch path from edit If ExplorerTitle Not Contains \ ControlGetText, ExplorerTitle, Edit1, A If ExplorerTitle Contains \ ; if not, it's My Computer, Control Panel etc. { If (LastCharacter <> "\") { ; Change the path to the Explorer path ControlSetText,, %ExplorerTitle%, ahk_id %ControlHwnd% ControlSend,, {Enter}, ahk_id %ControlHwnd% ; Put the original filename back in the dialog edit control ControlSetText,, %ControlText%, ahk_id %ControlHwnd% } ; For cases like 7-Zip "Extract" dialog which contain pathnames, not filenames Else ControlSetText,, %ExplorerTitle%\, ahk_id %ControlHwnd% } ; Back to where we started... WinActivate, ahk_class %DialogClass% ControlHwnd = DialogClass = } } }} ; See http://www.autohotkey.com/forum/topic35659.htmlHookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime ){ global ControlHwnd global DialogClass If Event ; EVENT_SYSTEM_FOREGROUND = 0x3 { ; Windows and dialog boxes need time to "settle". See AHK manual Sleep, 120 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 OfficeDialog := True If ( DialogClass = "#32770" || OfficeDialog ) { ; Get control handle of edit for use in ShellMessage() EditClass = Edit1 ; Default If OfficeDialog 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){ DllCall("CoInitialize", Uint, 0) return DllCall("SetWinEventHook" , Uint,eventMin , Uint,eventMax , Uint,hmodWinEventProc , Uint,lpfnWinEventProc , Uint,idProcess , Uint,idThread , Uint,dwFlags)} UnhookWinEvent(){ Global DllCall( "UnhookWinEvent", Uint,hWinEventHook ) DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback} HandleExit:UnhookWinEvent()ExitAppReturn
Greetz Winkie
-Winkie (April 09, 2010, 05:54 PM)
--- End quote ---
Winkie I received this error in the script
IDEA: Insta-switch file dialog to any Explorer window's path (code included)
Best Regards
Contro:
oohhh my god
At final I got close the script.
Always getting the message of the window above.
Uuffff
:-*
MilesAhead:
Here's a small contribution. If the active window is an Explorer window, these functions will get the path without reading the edit control or requiring Show Full Path in Title Bar. However, I don't think they work with Shell namespaces like libraries. I got these from AHK forum. I use AHK_L 32 bit Unicode for compiling.
--- ---; use #IfWinActive ahk_group ExplorerGroup
; to make sure the active window is an
; Explorer window before calling this function
;
ActiveFolderPath()
{
return PathCreateFromURL( ExplorerPath(WinExist("A")) )
}
; slightly modified version of function by jethrow
; on AHK forums.
;
ExplorerPath(_hwnd)
{
for Item in ComObjCreate("Shell.Application").Windows
if (Item.hwnd = _hwnd)
return, Item.LocationURL
}
; function by SKAN on AHK forums
;
PathCreateFromURL( URL )
{
VarSetCapacity( fPath, Sz := 2084, 0 )
DllCall( "shlwapi\PathCreateFromUrl" ( A_IsUnicode ? "W" : "A" )
, Str,URL, Str,fPath, UIntP,Sz, UInt,0 )
return fPath
}
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version