Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Initial window position – Run from a toolbar button
#6
On my PC, folder dialog position does not depend on owner window. Didn't notice it in any OS version.
In next QM version the function will have hwndowner parameter, and will not use the active window as owner if it does not belong to current thread. Same as with OpenSaveDialog.

Function BrowseForFolder
Code:
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 - receives full path of selected folder.
;initdir - initially display this folder in the dialog.
;;;On Windows 2000 initdir does not work with flag 4.
;flags:
;;;1, 2, 4 - see above.
;;;Flag 4 changes dialog style, adds more features.
;;;Also can include BIF_x flags (see <google "site:microsoft.com BROWSEINFO">BROWSEINFO</google>), lshifted 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. 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.

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


BROWSEINFOW b
if(!hwndowner) hwndowner=win; if(GetWindowThreadProcessId(hwndowner 0)!=GetCurrentThreadId) hwndowner=0
b.hwndOwner=hwndowner
if(flags&1) b.ulFlags|BIF_BROWSEINCLUDEFILES
if(flags&2=0) b.ulFlags|BIF_RETURNONLYFSDIRS
if(flags&4) b.ulFlags|BIF_USENEWUI
b.ulFlags|flags>>8
b.lpszTitle=@text
if(flags&4)
,STRINT p.i=flags; p.s.searchpath(initdir)
,b.lpfn=&BFF_Callback; b.lParam=&p
else if(!empty(initdir)) b.pidlRoot=PidlFromStr(initdir)

ITEMIDLIST* pidl=SHBrowseForFolderW(&b)

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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)