Re: SHBrowseForFolder

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Derek Parnell wrote:
>> I don't remember getting this. Anyhow, there is a Windows API function 
>> all
>> "SHBrowseForFolder". It looks a bit complicated to use so I'll do some
>> experiments with it first. Feel free to do some research of your own 
>> though.
> Derek,

> I too have worked with this API and got bogged down when it came to 
> retrieving the full path from the ITEMIDLIST structure.  Here's the code 
> up to where I left off (I was having trouble getting the length of the 
> first item in the list):

> include win32lib.ew
> with trace

> atom xSHBrowseForFolder, binfo, result, rtn_code, cb1, cb2
> sequence folder, folder_path

> xSHBrowseForFolder = registerw32Function(shell32, "SHBrowseForFolder", 
> {C_POINTER}, C_POINTER)

> global constant
> bfOwner = allot( Long ),
> bfpidlRoot = allot( Long ),
> bfDisplayName = allot( Lpsz ),
> bfTitle = allot( Lpsz ),
> bfFlags = allot( Long ),
> bfFunction = allot( Long ),
> bfParam = allot( Long ),
> bfImage = allot( Long ),
> SIZEOF_BROWSEINFO = allotted_size()

> binfo = acquire_mem(0, SIZEOF_BROWSEINFO)

> store( binfo, bfOwner, 0)
> store( binfo, bfpidlRoot, NULL)
> store( binfo, bfDisplayName, "")
> store( binfo, bfTitle, "Select a Folder")
> store( binfo, bfFlags, NULL)
> store( binfo, bfFunction, NULL)
> store( binfo, bfParam, NULL)
> store( binfo, bfImage, NULL)

> result = w32Func(xSHBrowseForFolder, {binfo})
> folder = fetch( binfo, bfDisplayName )
> trace(1)
> cb1 = peek(result)
> cb2 = peek(result)
> folder_path = peek({result+2,cb1-2})
> rtn_code = message_box("Folder: " & folder_path, "Test", MB_OK)
> release_mem(binfo)

> With this code the dialog does appear and you can select a folder but I 
> can't seem to figure out how to get the path from "result".  I will keep 
> plugging away and maybe between the two of us we can figure it out.  I 
> have some places where I would also like to select a folder.

> Jonas

You need to user SHGetPathFromIDList (from user32.dll, takes a LONG and a
string pointer) on "result", something like:

folder = allocate_string(repeat(512,0))
if w32Func(xSHGetPathFromIDList,{result,folder}} then
   --the string pointed to by folder now contains the path
end if

That code is totally untested because I really want to get some sleep
soon :) I'll try and do it properly sometime tomorrow :)

Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.rat-software.com/
Please leave quoted text in place when replying

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu