I'm developing a shell extension that creates a new folder. I'd like the new folder to display a set of custom columns in details view once the user browses into it. I thought that maybe IColumnManager was the correct interface to accomplish this. This is the code I'm trying after the new folder has been created (I've abbreviated the PKEYs):
IShellFolder* psdf;
if (SUCCEEDED(SHGetDesktopFolder(&psdf))) {
PIDLIST_ABSOLUTE pidl = ILCreateFromPath(pwszNewFolderPath);
LPSHELLFOLDER psf;
if (SUCCEEDED(psdf->BindToObject(pidl, NULL, IID_IShellFolder, (void**)& psf))) {
SFV_CREATE sfvc = { 0 };
sfvc.cbSize = sizeof(SFV_CREATE);
sfvc.pshf = psf;
sfvc.psvOuter = NULL;
sfvc.psfvcb = NULL;
LPSHELLVIEW psv;
if (SUCCEEDED(SHCreateShellFolderView(&sfvc, &psv))) {
IColumnManager* pcm;
if (SUCCEEDED(psv->QueryInterface(IID_IColumnManager, (void**)& pcm))) {
PROPERTYKEY rgkeys[] = {
PKEY_ [...] ,
PKEY_ [...] ,
PKEY_ [...] ,
};
if (SUCCEEDED(pcm->SetColumns(rgkeys, ARRAYSIZE(rgkeys)))) {
//MessageBoxA(NULL, "Success?", "Success?", MB_OK);
}
pcm->Release();
}
psv->Release();
}
psf->Release();
}
psdf->Release();
}
This code successfully executes each method call, but when I go into the newly created folder, the columns aren't as desired. Am I doing something wrong? Does IColumnManager work only when a given folder is already visible? Maybe it's only for IExplorerBrowser or something? And if it's not the right interface, how can I set a set of custom columns for when the user browses into a folder? Thanks.
EDIT: This code actually works on an active view of the folder. However, the changes it makes to the columns do not persist (unlike column changes made manually by the user, which do persist). So I guess I'm wondering if there's a way to make them persist, or if there's another approach to set columns without requiring an active view. Thanks again.
Also, might SHGetViewStatePropertyBag be relevant? Along with IExplorerBrowser::SetPropertyBag? Or could those not be used for regular shell folders?