Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

specifying root folder when using BrowseForFolder

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I'm using the BrowseForFolder function in MS VC++ and when the dialog box opens I would like it to goto another folder and not the desktop. Can someone help me do this?
 
Yes it is posible but it'a a little tricky.
The single argument of this function is a pointer to a BROWSEINFO structure used as [in,out].

You should fill the pidlRoot(LPCITEMIDLIST type) member of this structure with the ITEMIDLIST of the folder you want your folder dialog to start with.

Below is an example function from MSDN:

LPITEMIDLIST PidlBrowse(HWND hwnd, int nCSIDL, LPSTR pszDisplayName)
{
LPITEMIDLIST pidlRoot = NULL;
LPITEMIDLIST pidlSelected = NULL;
BROWSEINFO bi = {0};
LPMALLOC pMalloc = NULL;

SHGetMalloc(&pMalloc);

if(nCSIDL)
{
SHGetFolderLocation(hwnd, nCSIDL, NULL, NULL, &pidlRoot);
}

else
{
pidlRoot = NULL;
}

bi.hwndOwner = hwnd;
bi.pidlRoot = pidlRoot;
bi.pszDisplayName = pszDisplayName;
bi.lpszTitle = "Choose a folder";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;

pidlSelected = SHBrowseForFolder(&bi);

if(pidlRoot)
{
pMalloc->Free(pidlRoot);
}
pMalloc->Release();
return pidlSelected;
}


HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
On the same topic, let's say I want the root folder to be a specific computer on the network. I have a PIDL that points to Network Neighborhood; how do I get it to start from the specific computer I want?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top