-- Browse.ew converted by Jeffrey Fielding (JJProg@cyberbury.net) -- from VB code by Brad Martinez -- Usage: -- path = DoBrowseForFolder(title, hwnd) -- Will return 0 on error, or the selected path. -- title is the title for the dialog box -- hwnd is the hwnd of the window the dialog is associated with include machine.e include dll.e constant BIF_RETURNONLYFSDIRS = #1 constant SHITEMID_CB = 0, SHITEMID_ABID = 4, SIZEOF_SHITEMID = 8 constant SHELL32 = open_dll("shell32") constant SHGetPathFromIDList = define_c_func(SHELL32, "SHGetPathFromIDListA",{C_LONG, C_POINTER}, C_LONG) constant SHGetSpecialFolderLocation = define_c_func(SHELL32, "SHGetSpecialFolderLocation",{C_LONG,C_LONG,C_POINTER},C_LONG) constant OLE32 = open_dll("ole32") constant CoTaskMemFree = define_c_proc(OLE32,"CoTaskMemFree",{C_LONG}) constant SHBrowseForFolder = define_c_func(SHELL32, "SHBrowseForFolderA",{C_POINTER},C_LONG) constant BI_hOwner = 0, BI_pidlRoot = 4, BI_pszDisplayName = 8, BI_lpszTitle = 12, BI_ulFlags = 16, BI_lpfn = 20, BI_lParam = 24, BI_iImage = 28, SIZEOF_BI = 32 constant MAX_PATH = 260, SIZEOFszTYPENAME = 80 constant SHFILEINFO_hIcon = 0, SHFILEINFO_iIcon = 4, SHFILEINFO_dwAttributes = 8, SHFILEINFO_szDisplayName = 12, SHFILEINFO_szTypeName = 16, SIZEOF_SHFILEINFO = 20 global function DoBrowseForFolder(sequence title, atom hwnd) atom BI, nFolder, IDL, pIdl, sPath, displayName, lpszTitle, junk sequence ret BI = allocate(SIZEOF_BI) IDL = allocate(SIZEOF_SHITEMID) poke4(IDL,{0,0}) ret = "" poke4(BI,repeat(0,8)) poke4(BI+BI_hOwner, hwnd) nFolder = 0 if c_func(SHGetSpecialFolderLocation,{hwnd,nFolder,IDL}) = 0 then poke(BI+BI_pidlRoot, peek({IDL+SHITEMID_CB, 4})) end if displayName = allocate_string(repeat(0,MAX_PATH)) poke4(BI+BI_pszDisplayName,displayName) lpszTitle = allocate_string(title) poke4(BI+BI_lpszTitle, lpszTitle) poke4(BI+BI_ulFlags, BIF_RETURNONLYFSDIRS) pIdl = c_func(SHBrowseForFolder,{BI}) if pIdl = 0 then free(IDL) free(lpszTitle) free(displayName) free(BI) return 0 end if sPath = allocate_string(repeat(0,MAX_PATH)) junk = c_func(SHGetPathFromIDList,{pIdl,sPath}) ret = peek({sPath,MAX_PATH+1}) ret = ret[1..find(0,ret)] c_proc(CoTaskMemFree,{pIdl}) free(sPath) free(lpszTitle) free(displayName) free(BI) free(IDL) return ret end function
Make your own free website on Tripod.com