If I don't add an asterisk in front of path,it looks good and makes things easier but you can't select any other location outside the start location
If I add an asterisk then I can select whatever folder I want(which is what I want)but the problem is,the folder is not focused,I have to always scroll to it(it is selected but not focused)
I'm on Win7 and I'm using AHK 1.1.23
Problem with FileSelectFolder start location
Re: Problem with FileSelectFolder start location
I have been trying to solve your problem, without any luck, here is the current code maybe someone else can correct it.
In the meantime here is a workaround.
Code: Select all
TVN_SELCHANGED := -402
OnMessage(TVN_SELCHANGED, "Change")
FileSelectFolder, OutputVar, *C:\Program Files (x86)\Microsoft
ExitApp
Change(wParam, lParam, msg, hwnd){
TVM_ENSUREVISIBLE := 0x1114
SendMessage, %TVM_ENSUREVISIBLE%, 0, % lParam.itemNew, , ahk_id %hwnd%
}
Code: Select all
SetTimer, label, -100
FileSelectFolder, OutputVar, *C:\Program Files (x86)\Microsoft
ExitApp
label:
WinWaitActive, ahk_exe AutoHotkey.exe
Send, {Down}{Up}
return
Please excuse my spelling I am dyslexic.
Re: Problem with FileSelectFolder start location
This one is apparently a Windows bug: https://connect.microsoft.com/VisualStu ... -windows-7
This is using the workaround I found here to select the folder along with hooks to get the SHBrowseForFolder's HWND:
If using a hook (although this one is just targeting its own process only) is unacceptable to you, or you'd rather just use something less convoluted, look at this topic: https://autohotkey.com/boards/viewtopic.php?t=8928
This is using the workaround I found here to select the folder along with hooks to get the SHBrowseForFolder's HWND:
Code: Select all
#NoEnv
SetBatchLines, -1
ShellProc(nCode, wParam, lParam)
{
global bffHwnd, wndhook, shellhk
; Remove unneeded WndRetProc hook as we should already have the HWND if we're in this function
if (wndhook)
DllCall("UnhookWindowsHookEx", "Ptr", wndhook), wndhook := 0
if (nCode == 4 && wParam == bffHwnd)
{
Critical
; HSHELL_WINDOWACTIVATED with the folder browse dialog
; Perform voodoo I found on the Internet to select the folder
SendMessage, 0x110A, 0x0009, 0, SysTreeView321, ahk_id %bffHwnd% ; TVM_GETNEXTITEM, TVGN_CARET
item := ErrorLevel
Sleep 100
PostMessage, 0x1114, 0, %item%, SysTreeView321, ahk_id %bffHwnd% ; TVM_ENSUREVISIBLE
bffHwnd := 0
; Remove this shell hook
if (shellhk)
DllCall("UnhookWindowsHookEx", "Ptr", shellhk), shellhk := 0
Critical, Off
}
return DllCall("CallNextHookEx", "Ptr", 0, "Int", nCode, "UPtr", wParam, "UPtr", lParam, "UPtr")
}
CallWndRetProc(nCode, wParam, lParam)
{
if (nCode >= 0) ; HC_ACTION
{
message := NumGet(lParam+0, A_PtrSize == 8 ? 24 : 12, "UInt")
if (message == 0x467)
{
Critical
;OutputDebug BFFM_SETSELECTIONW
; Store HWND of the SHBrowseForFolder dialog
global bffHwnd := NumGet(lParam+0, A_PtrSize == 8 ? 32 : 16, "Ptr")
; This function is blocking, and the window isn't visible yet, so create a shell hook to find the window once it's visible and activated
global shellhk := DllCall("SetWindowsHookEx", "Int", WH_SHELL := 10, "Ptr", global shellhklpfn := RegisterCallback("ShellProc", ""), "Ptr", 0, "UInt", DllCall("GetCurrentThreadId", "UInt"), "Ptr")
Critical, Off
}
}
return DllCall("CallNextHookEx", "Ptr", 0, "Int", nCode, "UPtr", wParam, "UPtr", lParam, "UPtr")
}
; Monitor messages sent to know when BFFM_SETSELECTION is sent to the folder browse dialog inside the callback: https://github.com/Lexikos/AutoHotkey_L/blob/HEAD/source/script_autoit.cpp#L1112
wndhook := DllCall("SetWindowsHookEx", "Int", WH_CALLWNDPROCRET := 12, "Ptr", wndlpfn := RegisterCallback("CallWndRetProc", ""), "Ptr", 0, "UInt", DllCall("GetCurrentThreadId", "UInt"), "Ptr")
FileSelectFolder, OutputVar, *C:\UT2004
; Free RegisterCallback-allocated memory - if you must. To make sure this doesn't crash, rework this to make sure you know the hooks are unhooked first
;if (wndlpfn)
; DllCall("GlobalFree", "Ptr", wndlpfn, "Ptr"), wndlpfn := 0
;if (shellhklpfn)
; DllCall("GlobalFree", "Ptr", shellhklpfn, "Ptr"), wndlpfn := 0
ExitApp
Re: Problem with FileSelectFolder start location
Found a way.
Code: Select all
SetTimer, label, -100
FileSelectFolder, OutputVar, *C:\Program Files (x86)\Microsoft
ExitApp
label:
TVM_ENSUREVISIBLE := 0x1114
TVM_GETNEXTITEM := 0x110A
TVGN_NEXTSELECTED := 0x000B
SendMessage, %TVM_GETNEXTITEM%, %TVGN_NEXTSELECTED%, 0, SysTreeView321, ahk_exe AutoHotkey.exe
SendMessage, %TVM_ENSUREVISIBLE%, 0, %ErrorLevel%, SysTreeView321, ahk_exe AutoHotkey.exe
return
Please excuse my spelling I am dyslexic.
Who is online
Users browsing this forum: Perpendie and 215 guests