Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BrowseForFolder initial folder
Dear Gintaras, I would appreciate it if you could kindly give some advice to the following issue:

BrowseForFolder(sf "$windows$\system32" 2)

shows folder "system32" but it cannot browse upwards.

BrowseForFolder(sf "$windows$\system32" 4)

shows folder "$windows$" and then you have to browse manually to system32.

I wonder whether there exists an option to use "4" and show directly "system32" .

Many thanks in advance.
In next QM version BrowseForFolder will have this code.

Function BrowseForFolder
Copy      Help
function# str&s [$initDir] [flags] [$text] [hwndOwner] ;;flags: 1 include files, 2 include non-file objects (Control Panel, etc), 4 new style

;Shows "Browse For Folder" dialog for selecting a folder.
;Returns a nonzero value on OK, 0 on Cancel.

;s - variable that receives full path of selected folder.
;;;With flag 2 it is <help #IDP_SEARCHPATHS>ITEMIDLIST string</help> if a non-file object selected.
;initDir - initially display this folder in the dialog.
;;;Without flag 4 displays only this folder and subfolders. With flag 4 displays all folders and selects/expands this folder.
;;;1, 2, 4 - see above.
;;;Flag 4 changes dialog style, adds more features.
;;;Also can include BIF_x flags (see <google " BROWSEINFO">BROWSEINFO</google>), left-shifted by 8 bits. For example, to browse for computer, use 2|(WINAPI.BIF_BROWSEFORCOMPUTER<<8).
;text - text to display above the folder list.
;hwndOwner (QM 2.3.4) - owner window handle. It will be disabled.
;;;If omitted or 0, will use the active window, if it belongs to current thread. To create unowned dialog, use GetDesktopWindow for hwndOwner.

;str s
;if(!BrowseForFolder(s "$windows$" 4)) ret
;out s

int expandedOnce

if(!hwndOwner) hwndOwner=win; if(GetWindowThreadProcessId(hwndOwner 0)!=GetCurrentThreadId) hwndOwner=0
if(flags&1) b.ulFlags|BIF_BROWSEINCLUDEFILES
if(flags&2=0) b.ulFlags|BIF_RETURNONLYFSDIRS
if(flags&4) b.ulFlags|BIF_USENEWUI
if(!empty(initDir)) ITEMIDLIST* initPidl=PidlFromStr(initDir)
if(flags&4) b.lpfn=&sub.Callback
else b.pidlRoot=initPidl ;;BFFM_SETEXPANDED does not work with old-style

ITEMIDLIST* pidl=SHBrowseForFolderW(&b)

if(pidl) PidlToStr(pidl &s flags&2=0); CoTaskMemFree pidl; else s.all
CoTaskMemFree initPidl
ret s.len

#sub Callback v
function# hwnd uMsg lParam !*lpData

sel uMsg
,if(initPidl) SendMessage hwnd BFFM_SETEXPANDED 0 initPidl
,if initPidl and flags&4 and !expandedOnce and IsWindowVisible(hwnd)
,,int c=child("" "SysTreeView32" hwnd)
,,int hsel=SendMessage(c TVM_GETNEXTITEM TVGN_CARET 0)
,,SendMessage(c TVM_ENSUREVISIBLE 0 hsel) ;;workaround for API bug: does not scroll to the selected folder
,,SendMessage(c TVM_EXPAND TVE_EXPAND hsel) ;;workaround for API bug: does not expand some folders, eg system32
,if(flags&6=4 and _winnt<6) SendMessage hwnd BFFM_ENABLEOK 0 PidlToStr(+lParam &_s 1) ;;xp bug fix
Many thanks indeed! Perfect!

Forum Jump:

Users browsing this thread: 1 Guest(s)