此代码的任何一个版本都可以正常工作,但是我的磁盘实用程序仅适用于物理文件夹,不适用于Workgroup。有什么方法可以将其限制为实际文件系统实体吗?
这是我当前的IFileDialog版本:
IFileDialog *pfd;
if ( CoCreateInstance( CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS( &pfd ) ) != S_OK ) {
AKS( AKSWarn, "CoCreateInstance() failed" );
return;
}
DWORD dwOptions;
pfd->GetOptions( &dwOptions );
pfd->SetOptions( dwOptions | FOS_PICKFOLDERS );
if ( pfd->Show( NULL ) != S_OK ) {
AKS( AKSWarn, "IFileDialog::Show() failed" );
pfd->Release();
return;
}
IShellItem *psi;
if ( pfd->GetResult( &psi ) != S_OK ) {
AKS( AKSWarn, "IFileDialog::GetResult() failed" );
pfd->Release();
return;
}
LPWSTR pwcsChoice;
if ( psi->GetDisplayName( SIGDN_DESKTOPABSOLUTEPARSING,
&pwcsChoice ) != S_OK ) {
AKS( AKSWarn, "IFileDialog::GetResult() failed" );
psi->Release();
pfd->Release();
return;
}
char szChoice[ 500 ];
wcstombs( szChoice, pwcsChoice, sizeof( szChoice ) );
peditRoot->SetWindowText( szChoice );
CoTaskMemFree( pwcsChoice );
psi->Release();
pfd->Release();
使用我从MSFT网站获得的包装器函数调用SHBrowseForFolder():
static bool GetFolder( string& folderpath, const char* szCaption = NULL,
HWND hOwner = NULL ) {
bool retVal = false;
// The BROWSEINFO struct tells the shell
// how it should display the dialog.
BROWSEINFO bi = { 0 };
bi.ulFlags = BIF_USENEWUI;
bi.hwndOwner = hOwner;
bi.lpszTitle = szCaption;
// must call this if using BIF_USENEWUI
::OleInitialize( NULL );
// Show the dialog and get the itemIDList for the
// selected folder.
LPITEMIDLIST pIDL = ::SHBrowseForFolder( &bi );
if ( pIDL ) {
char szBuf[_MAX_PATH] = { '\0' };
if ( ::SHGetPathFromIDList( pIDL, szBuf ) ) {
// Set the string value.
folderpath = szBuf;
retVal = true;
} else
SCWinUtilMessageBoxVA( hOwner, "Error Browsing", MB_OK,
"This app can only work with actual disks or folders, not "
"Control Panel, Workgroup, etc." );
// free the item id list
CoTaskMemFree( pIDL );
}
::OleUninitialize();
return retVal;
}
堆栈溢出抱怨我提供了太多代码。因此,显然,我必须在底部添加一些文本以将其填充。堆栈溢出抱怨我提供了太多代码。因此,显然,我必须在底部添加一些文本以将其填充。堆栈溢出抱怨我提供了太多代码。因此,显然,我必须在底部添加一些文本以将其填充。堆栈溢出抱怨我提供了太多代码。因此,显然,我必须在底部添加一些文本以将其填充。