本文整理汇总了C++中IShellFolder::SetNameOf方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellFolder::SetNameOf方法的具体用法?C++ IShellFolder::SetNameOf怎么用?C++ IShellFolder::SetNameOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellFolder
的用法示例。
在下文中一共展示了IShellFolder::SetNameOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rename_shellfolder
// Use the IShellFolder API to rename the connection.
static HRESULT rename_shellfolder(PCWSTR wGuid, PCWSTR wNewName)
{
// This is the GUID for the network connections folder. It is constant.
// {7007ACC7-3202-11D1-AAD2-00805FC1270E}
const GUID CLSID_NetworkConnections = {
0x7007ACC7, 0x3202, 0x11D1, {
0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E
}
};
LPITEMIDLIST pidl;
IShellFolder *pShellFolder;
IMalloc *pShellMalloc;
// Build the display name in the form "::{GUID}".
if (wcslen(wGuid) >= MAX_PATH)
return E_INVALIDARG;
WCHAR szAdapterGuid[MAX_PATH + 2];
swprintf(szAdapterGuid, L"::%ls", wGuid);
// Initialize COM.
CoInitialize(NULL);
// Get the shell allocator.
HRESULT hr = SHGetMalloc(&pShellMalloc);
if (SUCCEEDED(hr))
{
// Create an instance of the network connections folder.
hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
CLSCTX_INPROC_SERVER, IID_IShellFolder,
reinterpret_cast<LPVOID *>(&pShellFolder));
}
// Parse the display name.
if (SUCCEEDED(hr))
{
hr = pShellFolder->ParseDisplayName(NULL, NULL, szAdapterGuid, NULL,
&pidl, NULL);
}
if (SUCCEEDED(hr))
{
hr = pShellFolder->SetNameOf(NULL, pidl, wNewName, SHGDN_NORMAL,
&pidl);
pShellMalloc->Free(pidl);
}
CoUninitialize();
return hr;
}
示例2: CoCreateInstance
//
// NB: This function leaks memory/references.
//
EXTERN_C void
RenameAdapter(const GUID *AdapterGuid, const WCHAR *NewName)
{
HRESULT hr;
IShellFolder *pShellFolder;
hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellFolder,
reinterpret_cast<LPVOID *>(&pShellFolder));
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: CoCreateInstance: %x\n", hr);
return;
}
LPOLESTR szClsId;
hr = StringFromCLSID(*AdapterGuid, &szClsId);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: StringFromCLSID: %x\n", hr);
return;
}
WCHAR szAdapterGuid[MAX_PATH];
swprintf(szAdapterGuid, L"::%s", szClsId);
LPITEMIDLIST pidl;
hr = pShellFolder->ParseDisplayName(NULL, NULL,
szAdapterGuid, NULL,
&pidl, NULL);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: ParseDisplayName: %x\n", hr);
return;
}
hr = pShellFolder->SetNameOf(NULL, pidl, NewName, SHGDN_NORMAL, &pidl);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: SetNameOf: %x\n", hr);
return;
}
}
示例3: Rename
//.........这里部分代码省略.........
CRenameDlg dlg(hwnd);
dlg.SetFileList(m_filelist);
if (dlg.DoModal(g_hInst, IDD_RENAMEDLG, hwnd, NULL) == IDOK)
{
try
{
const std::tr1::wregex regCheck(dlg.GetMatchString(), dlg.GetRegexFlags());
NumberReplaceHandler handler(dlg.GetReplaceString());
// start renaming the files
IServiceProvider * pServiceProvider = NULL;
if (SUCCEEDED(GetIServiceProvider(hwnd, &pServiceProvider)))
{
IShellBrowser * pShellBrowser;
if (SUCCEEDED(pServiceProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (LPVOID*)&pShellBrowser)))
{
IShellView * pShellView;
if (SUCCEEDED(pShellBrowser->QueryActiveShellView(&pShellView)))
{
IFolderView * pFolderView;
if (SUCCEEDED(pShellView->QueryInterface(IID_IFolderView, (LPVOID*)&pFolderView)))
{
// hooray! we got the IFolderView interface!
// that means the explorer is active and well :)
// but we also need the IShellFolder interface because
// we need its GetDisplayNameOf() method
IPersistFolder2 * pPersistFolder;
if (SUCCEEDED(pFolderView->GetFolder(IID_IPersistFolder2, (LPVOID*)&pPersistFolder)))
{
IShellFolder * pShellFolder;
if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder)))
{
// our next task is to enumerate all the
// items in the folder view and select those
// which match the text in the edit control
int nCount = 0;
if (SUCCEEDED(pFolderView->ItemCount(SVGIO_ALLVIEW, &nCount)))
{
for (int i=0; i<nCount; ++i)
{
LPITEMIDLIST pidl;
if (SUCCEEDED(pFolderView->Item(i, &pidl)))
{
STRRET str;
if (SUCCEEDED(pShellFolder->GetDisplayNameOf(pidl,
// SHGDN_FORPARSING needed to get the extensions even if they're not shown
SHGDN_INFOLDER|SHGDN_FORPARSING,
&str)))
{
TCHAR dispname[MAX_PATH];
StrRetToBuf(&str, pidl, dispname, _countof(dispname));
std::wstring replaced;
try
{
std::wstring sDispName = dispname;
// check if the item is in the list of selected items
if (m_filelist.find(sDispName) != m_filelist.end())
{
replaced = std::tr1::regex_replace(sDispName, regCheck, dlg.GetReplaceString());
replaced = handler.ReplaceCounters(replaced);
if (replaced.compare(sDispName))
{
ITEMIDLIST * pidlrenamed;
pShellFolder->SetNameOf(NULL, pidl, replaced.c_str(), SHGDN_FORPARSING|SHGDN_INFOLDER, &pidlrenamed);
// if the rename was successful, select the renamed item
if (pidlrenamed)
pFolderView->SelectItem(i, SVSI_CHECK|SVSI_SELECT);
}
}
}
catch (std::exception)
{
}
}
CoTaskMemFree(pidl);
}
}
}
pShellFolder->Release();
}
pPersistFolder->Release();
}
pFolderView->Release();
}
pShellView->Release();
}
pShellBrowser->Release();
}
pServiceProvider->Release();
}
}
catch (std::exception)
{
}
}
m_bDialogShown = FALSE;
}