I would like to ask about the FileSelectFolder command. I am well aware of the various options but when I use it as follows:
Code: Select all
FileSelectFolder, folder, *%A_Desktop%\zoo
Thank you for your help.
iPhilip
Code: Select all
FileSelectFolder, folder, *%A_Desktop%\zoo
Code: Select all
SetTimer, ScrollTreeview, -1000 ; see remarks about timers and FileSelectFolder
FileSelectFolder, folder, *%A_Desktop%\zoo
msgbox % "you have seleceted: " folder
return
ScrollTreeview:
while !WinExist("Browse For Folder") && (A_Index<50) ; just testing the window's existence
sleep 20
if !WinExist()
{
MsgBox, ,error, no window found
ExitApp
}
; get the selected item
SendMessage 0x110A, 0x0009, 0, SysTreeView321 ; TVM_GETNEXTITEM := 0x110A, TVGN_CARET := 0x0009
; make sure it's visible
SendMessage 0x1114, 0, ErrorLevel, SysTreeView321 ; TVM_ENSUREVISIBLE := 0x1114
/*
; OR: https://msdn.microsoft.com/en-us/library/windows/desktop/bb787577(v=vs.85).aspx > WM_VSCROLL
; you can scroll the treeview by sending WM_VSCROLL message, and test if the selected item is visible
SB_LINEUP := 0
SB_LINEDOWN := 1
SB_PAGEUP := 2
SB_PAGEDOWN := 3
SB_THUMBPOSITION := 4
SB_THUMBTRACK := 5
SB_TOP := 6
SB_BOTTOM := 7
SB_ENDSCROLL := 8
wParam := SB_PAGEDOWN
SendMessage, 0x115, wParam, 0, SysTreeView321 ;WM_VSCROLL:=0x115
*/
return
Code: Select all
SetTimer, Timer, 1
FileSelectFolder, folder, *%A_Desktop%\foo
MsgBox %folder%
Return
; See http://ahkscript.org/boards/viewtopic.php?t=4557&start=20 for a full list of constants
Timer:
IfWinExist Browse For Folder ahk_class #32770
{ ; get the selected item
SendMessage, 0x110A, 0x0009, 0, SysTreeView321 ; TVM_GETNEXTITEM := 0x110A, TVGN_CARET := 0x0009
; expand the list of child items
SendMessage, 0x1102, 0x0002, ErrorLevel, SysTreeView321 ; TVM_EXPAND := 0x1102, TVE_EXPAND := 0x0002
Sleep 10 ; wait for the item to expand
; get the number of visible items
SendMessage, 0x1110, 0, 0, SysTreeView321 ; TVM_GETVISIBLECOUNT := 0x1110
; scroll down so that the selected item is centered vertically
Loop % Round(ErrorLevel/2)-1
SendMessage, 0x0115, 1, 0, SysTreeView321 ; WM_VSCROLL := 0x0115, SB_LINEDOWN := 1
SetTimer, Timer, Off
}
Return
Code: Select all
SetTimer, Timer, 1
Process, Exist ; If the PID-or-Name parameter is blank, the script's own PID is retrieved
pid := ErrorLevel ; get the script's process ID
FileSelectFolder, folder, *%A_Desktop%\foo
MsgBox %folder%
Return
; See http://ahkscript.org/boards/viewtopic.php?t=4557&start=20 for a full list of constants
Timer:
IfWinExist Browse For Folder ahk_class #32770 ahk_pid %PID% ; make sure it's your own window
{ ; get the selected item
SendMessage, 0x110A, 0x0009, 0, SysTreeView321 ; TVM_GETNEXTITEM := 0x110A, TVGN_CARET := 0x0009
; expand the list of child items
SendMessage, 0x1102, 0x0002, ErrorLevel, SysTreeView321 ; TVM_EXPAND := 0x1102, TVE_EXPAND := 0x0002
Sleep 10 ; wait for the item to expand
; get the number of visible items
SendMessage, 0x1110, 0, 0, SysTreeView321 ; TVM_GETVISIBLECOUNT := 0x1110
; scroll down so that the selected item is centered vertically
Loop % Round(ErrorLevel/2)-1
SendMessage, 0x0115, 1, 0, SysTreeView321 ; WM_VSCROLL := 0x0115, SB_LINEDOWN := 1
SetTimer, Timer, Off
}
Return
Code: Select all
PID := DllCall("GetCurrentProcessId")
SetTimer, SelectFolder, 1
FileSelectFolder, folder, *%A_WinDir%\System32
MsgBox %folder%
Return
; See http://ahkscript.org/boards/viewtopic.php?t=4557&start=20 for a full list of constants
SelectFolder:
IfWinActive Browse For Folder ahk_class #32770 ahk_pid %PID% ; Wait for the window to be active
{ SendMessage, 0x110A, 0x0009, 0, SysTreeView321 ; Get the selected item - TVM_GETNEXTITEM := 0x110A, TVGN_CARET := 0x0009
hItem := ErrorLevel ; Save the item handle for use below
SendMessage, 0x1102, 0x0002, hItem, SysTreeView321 ; Expand the item - TVM_EXPAND := 0x1102, TVE_EXPAND := 0x0002
while !IsExpanded(hItem) ; Wait for the item to expand
Sleep 0
SendMessage, 0x1110, 0, 0, SysTreeView321 ; Get the number of visible items - TVM_GETVISIBLECOUNT := 0x1110
Loop % Round(ErrorLevel/2)-1 ; Scroll down so that the selected item is centered vertically
SendMessage, 0x115, 1, 0, SysTreeView321 ; WM_VSCROLL := 0x0115, SB_LINEDOWN := 1
SetTimer, SelectFolder, Off
}
Return
; Reference: http://ahkscript.org/boards/viewtopic.php?p=29502#p29502
IsExpanded(hItem)
{ SendMessage, 0x1127, hItem, 0, SysTreeView321 ; Get the state of the item - TVM_GETITEMSTATE := 0x1127
Return (ErrorLevel & 0x0020) >> 5 ; Determine if the item is expanded - TVIS_EXPANDED := 0x0020
}