Article ID: 179900
Article Last Modified on 7/11/2005
178665 SAMPLE: RegView.exe: Shell Namespace Extension Example
STDMETHODIMP CShellFolder::GetAttributesOf( UINT uCount,
LPCITEMIDLIST aPidls[],
LPDWORD pdwAttribs)
{
UINT i;
for(i = 0; i < uCount; i++)
{
DWORD dwAttribs = 0;
// Is this item a folder?
if(IsFolder(aPidls[i]))
{
dwAttribs |= SFGAO_FOLDER;
// Does this folder item have any subfolders?
if(HasSubFolders(aPidls[i]))
dwAttribs |= SFGAO_HASSUBFOLDER;
// Can this folder be renamed?
if(CanRename(aPidls[i]))
dwAttribs |= SFGAO_CANRENAME;
}
/*
On entry, *pdwAttributes contains the attributes that are being
requested, so just use it as a mask.
*/
*pdwAttribs &= dwAttribs;
}
return S_OK;
}
#define IDM_MYRENAME 0
#define IDM_LAST 5
STDMETHODIMP CContextMenu::QueryContextMenu( HMENU hMenu,
UINT indexMenu,
UINT idCmdFirst,
UINT idCmdLast,
UINT uFlags)
{
if(!(CMF_DEFAULTONLY & uFlags))
{
MENUITEMINFO mii;
// Add any other menu items here.
if(uFlags & CMF_CANRENAME)
{
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE;
mii.wID = 0;
mii.fType = MFT_SEPARATOR;
InsertMenuItem( hMenu,
indexMenu++,
TRUE,
&mii);
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
mii.wID = idCmdFirst + IDM_MYRENAME;
mii.fType = MFT_STRING;
mii.dwTypeData = TEXT("&Rename");
mii.fState = (CanRenameItems() ? MFS_ENABLED : MFS_DISABLED);
InsertMenuItem( hMenu,
indexMenu++,
TRUE,
&mii);
}
// Add the following menu items here.
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(IDM_LAST + 1));
}
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0));
}
BOOL CContextMenu::CanRenameItems(void)
{
if(m_aPidls)
{
// Get the number of items assigned to this object.
UINT i;
for(i = 0; m_aPidls[i]; i++)
{
}
// You can't rename more than one item at a time.
if(i > 1)
return FALSE;
DWORD dwAttributes = SFGAO_CANRENAME;
m_pSFParent->GetAttributesOf(i, (LPCITEMIDLIST*)m_aPidls,
&dwAttributes);
return dwAttributes & SFGAO_CANRENAME;
}
return FALSE;
}
STDMETHODIMP CContextMenu::GetCommandString( UINT idCommand,
UINT uFlags,
LPUINT lpReserved,
LPTSTR lpszName,
UINT uMaxNameLen)
{
HRESULT hr = E_INVALIDARG;
switch(uFlags)
{
case GCS_VERBA:
switch(idCommand)
{
case IDM_MYRENAME:
lstrcpynA((LPSTR)lpszName, "rename", uMaxNameLen);
hr = NOERROR;
break;
}
break;
/*
Windows NT 4.0 with Internet Explorer 3.0x or no Internet Explorer
will always call this with GCS_VERBW. In this case, you need to do
the lstrcpyW to the pointer passed.
*/
case GCS_VERBW:
switch(idCommand)
{
case IDM_MYRENAME:
lstrcpynW((LPWSTR)lpszName, L"rename", uMaxNameLen);
hr = NOERROR;
break;
}
break;
}
return hr;
}
178665 SAMPLE: RegView.exe: Shell Namespace Extension Example
Keywords: kbhowto kbextension kbnamespace KB179900