Browsing for a folder (Windows)

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Browsing for a folder (Windows)

Post by hgm »

WinBoard currently calls SHBrowseForFolder to let the user select a folder. But this seems to always start at the root (Desktop or My Computer), which is extremely clumsy if you want to select from a set of folders many, many levels deep. I could not find any way to pop it up inside a folder close to the last-selected folder (say its parent, so that you can select a sibling with a single mouse click).

The browse dialog for normal files (GetOpenFileName) does have the property that it starts where you left it last time. But I could not figure out a way to use that to select folders.

Is Windows really such a moronically challenged OS, or am I overlooking something?
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Browsing for a folder (Windows)

Post by mar »

From what I have read I guess you have to play with the callback function, intercept BFFM_INITIALIZED and then use SendMessage back to the dialog with BFFM_SETSELECTION to set a new initial dir. Never tried that though.
Hope it helps.
Is Windows really such a moronically challenged OS, or am I overlooking something?
Yes, WinAPI is pain.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Browsing for a folder (Windows)

Post by hgm »

OK, that did it! Thanks!

The folder-browse buttons work really cool now: I feed them the text in the text-edit for which they are browsing as initial path, so that you immediately see all sibling folders around it. Ideal for selecting the piece directory.

I guess I should do something similar in the file-browse dialog (GetOpenFileName), which does have a standard parameter for the folder you should start in. In general it would be much better to start in the folder that contained the file currently selected for that field, as in the folder that contained the file you last opened.