I have a MFC application that uses IExplorerBrowser interface to implement the windows shell inside my application. In this application, I have a button that user can click and create a folder inside the shell view of the explorer. After the folder gets created, the application should allow the user to rename the folder. In other words, I want it to work exactly the same way as user creates folder in the Windows explorer. I used NewItem method of IFileOperations interface to create the folder. Here is my exact code of creating a folder inside my application
HRESULT CreateFolder( __in IShellItem *pDestinationFolder, PCWSTR pszNewName )
{
HRESULT hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE );
if ( SUCCEEDED( hr ) )
{
CComPtr<IFileOperation> pFileOperation;
hr = CoCreateInstance( CLSID_FileOperation,
NULL,
CLSCTX_ALL,
IID_PPV_ARGS( &pFileOperation ) );
if ( SUCCEEDED( hr ) )
{
hr = pFileOperation->SetOperationFlags( FOF_NO_UI );
if ( SUCCEEDED( hr ) )
{
hr = pFileOperation->NewItem( pDestinationFolder, FILE_ATTRIBUTE_DIRECTORY, pszNewName, NULL, NULL );
if ( SUCCEEDED( hr ) )
{
hr = pFileOperation->PerformOperations();
}
}
}
}
CoUninitialize();
return hr;
}
After I call CreateFolder(...), I put the folder to select mode by using the SelectItem method of IFolderView2 interface. Here is the code to put the folder in Edit mode:
HRESULT hr = m_pIExplorerBrowser->GetCurrentView( IID_PPV_ARGS( pFolderView2 ) );
if( SUCCEEDED( hr ) )
pFolderView2->SelectItem( nLastCreatedFolderIndex, SVSI_EDIT );
The problem is that CreateFolder finishes later than my SelectItem method call. I have been looking for an event that will tell me when the view gets updated by CreateFolder so that i can send my SelectItem method after that.
Any help on this issue would be greatly appreciated.
I finally found the answer to my question. It was already asked as another question on stackoverflow. What is the "Shell Namespace" way to create a new folder?