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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SH Dialog Box - Set default directory?

Status
Not open for further replies.

Skute

Programmer
Joined
Jul 21, 2003
Messages
272
Location
GB
Hi,

does anyone know howto set the default opening directory for the directory browsing dialog? (SHDialog)

It always opens up in the root directory at the moment which is quite inconvenient!

Thanks
 
Never heard of SHDialog, but in SHBrowseForFolder you pass a BROWSEINFO structure as in parameter.
Specify a callback function that acts on BFFM_INITIALIZED and selects the desired folder.

See Q179378 in MSDN.


/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
with the SHBrowseForDialog, is it necessary to use the IMalloc structure?

I have been using SHBrowseForDialog for ages without using IMalloc, but after reading that article i tried it but it just caused an exception (invalid memory address on free).

The code im using is here:

void ChooseDirectory(HWND hwnd, char* Directory)
{
//LPITEMIDLIST pidlRoot = NULL;
LPITEMIDLIST pidlSelected = NULL;
BROWSEINFO bi = {0};
LPMALLOC pMalloc;

char strFoldername[MAX_PATH] = &quot;&quot;;
char strDirectory[MAX_PATH] = &quot;&quot;;
char* pRelative = NULL;

if (SUCCEEDED(SHGetMalloc(&pMalloc)))
{
ZeroMemory(&bi,sizeof(bi));
bi.hwndOwner = hwnd;
bi.pidlRoot = 0;
bi.pszDisplayName = strFoldername;
bi.lpszTitle = &quot;Choose a directory&quot;;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;

pidlSelected = SHBrowseForFolder(&bi);

if (pidlSelected)
{
SHGetPathFromIDList(pidlSelected, strFoldername);

if (strlen(strFoldername) > 0)
{
GetCurrentDirectory(MAX_PATH, strDirectory);
_strlwr(strDirectory);
_strlwr(strFoldername);
pRelative = strstr(strFoldername, strDirectory);
if (pRelative == NULL)
strcpy(Directory, strFoldername);
else
{
pRelative = pRelative + strlen(strDirectory);
strcpy(Directory, &quot;.&quot;);
strcpy(Directory + 1, pRelative);
}
}

pMalloc->Free(pMalloc);
}

pMalloc->Release();
}
}


Can you spot anything wrong? Is it necessary to have the pMalloc structure?
 
(oh btw, thanks for the link, the callback function worked great!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top