如何删除回收站里面的指定文件
时间:2010-02-21
来源:互联网
我已经可以通过 BindToObject 和 EnumObjects 这种COM API枚举出回收站里面的文件了,但是如果我想要删除回收站里面的指定文件,无法实现。
我只找到清空回收站的API: SHEmptyRecycleBin
我只找到清空回收站的API: SHEmptyRecycleBin
作者: hsly110 发布时间: 2010-02-21
http://vcdotnet.phpchinaz.cn/archives/196624
作者: oldmanzhao 发布时间: 2010-02-21
参数:pidl:回收站枚举出来的对象. lpszCommand:所要进行的操作.如delete,undelete等.
BOOL ExecCommand(LPITEMIDLIST pidl, LPCTSTR lpszCommand)
{
BOOL bReturn = FALSE;
LPCONTEXTMENU pCtxMenu = NULL;
HRESULT hr = S_OK;
if(pidl == NULL)
return false;
if (NULL != m_pFolder2)
{
hr = m_pFolder2->GetUIObjectOf (m_hWnd, 1, (LPCITEMIDLIST *)&pidl, IID_IContextMenu, NULL, (LPVOID *)&pCtxMenu);
STRRET strret;
m_pFolder2->GetDisplayNameOf(pidl,SHGDN_NORMAL,&strret);
TCHAR szTemp[MAX_PATH];
WideCharToMultiByte (CP_ACP, 0, strret.pOleStr, -1, szTemp, sizeof (szTemp), NULL, NULL);
}
if (SUCCEEDED (hr))
{
UINT uiID = UINT (-1);
UINT uiCommand = 0;
UINT uiMenuFirst = 1;
UINT uiMenuLast = 0x00007FFF;
HMENU hmenuCtx;
int iMenuPos = 0;
int iMenuMax = 0;
TCHAR szMenuItem[128];
TCHAR szTrace[512];
char verb[MAX_PATH] ;
hmenuCtx = CreatePopupMenu();
hr = pCtxMenu->QueryContextMenu(hmenuCtx, 0, uiMenuFirst, uiMenuLast, CMF_NORMAL);
iMenuMax = GetMenuItemCount(hmenuCtx);
wsprintf (szTrace, _T("Nb Items added to the menu %d\n\n"), iMenuMax);
TRACE (szTrace);
for (iMenuPos = 0 ; iMenuPos < iMenuMax; iMenuPos++)
{
GetMenuString(hmenuCtx, iMenuPos, szMenuItem, sizeof (szMenuItem), MF_BYPOSITION) ;
wsprintf (szTrace, _T("Menu Entry : %s\n"), szMenuItem);
TRACE (szTrace);
uiID = GetMenuItemID(hmenuCtx, iMenuPos) ;
if ((uiID == -1) || (uiID == 0))
{
wsprintf (szTrace, _T("No Verb found for the entry #%d \n\n"), uiID);
TRACE (szTrace);
}
else
{
hr = pCtxMenu->GetCommandString(uiID-1, GCS_VERBA, NULL, verb, sizeof (verb));
if (FAILED (hr))
{
verb[0] = TCHAR ('\0') ;
}
else
{
if (0 == _tcsicmp (verb, lpszCommand))
{
uiCommand = uiID-1 ;
}
}
wsprintf (szTrace, _T("verb %s (ret %d)\n\n"), verb, hr);
TRACE (szTrace);
}
}
if ((UINT)-1 != uiCommand)
{
CMINVOKECOMMANDINFO cmi;
ZeroMemory(&cmi, sizeof(CMINVOKECOMMANDINFO));
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = CMIC_MASK_FLAG_NO_UI;
cmi.hwnd = m_hWnd;
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.lpVerb = MAKEINTRESOURCE (uiCommand);
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = NULL;
cmi.hIcon = NULL;
hr = pCtxMenu->InvokeCommand(&cmi);
if (SUCCEEDED (hr))
{
bReturn = TRUE;
}
}
}
if(pCtxMenu!=NULL)
pCtxMenu->Release();
return bReturn;
}
BOOL ExecCommand(LPITEMIDLIST pidl, LPCTSTR lpszCommand)
{
BOOL bReturn = FALSE;
LPCONTEXTMENU pCtxMenu = NULL;
HRESULT hr = S_OK;
if(pidl == NULL)
return false;
if (NULL != m_pFolder2)
{
hr = m_pFolder2->GetUIObjectOf (m_hWnd, 1, (LPCITEMIDLIST *)&pidl, IID_IContextMenu, NULL, (LPVOID *)&pCtxMenu);
STRRET strret;
m_pFolder2->GetDisplayNameOf(pidl,SHGDN_NORMAL,&strret);
TCHAR szTemp[MAX_PATH];
WideCharToMultiByte (CP_ACP, 0, strret.pOleStr, -1, szTemp, sizeof (szTemp), NULL, NULL);
}
if (SUCCEEDED (hr))
{
UINT uiID = UINT (-1);
UINT uiCommand = 0;
UINT uiMenuFirst = 1;
UINT uiMenuLast = 0x00007FFF;
HMENU hmenuCtx;
int iMenuPos = 0;
int iMenuMax = 0;
TCHAR szMenuItem[128];
TCHAR szTrace[512];
char verb[MAX_PATH] ;
hmenuCtx = CreatePopupMenu();
hr = pCtxMenu->QueryContextMenu(hmenuCtx, 0, uiMenuFirst, uiMenuLast, CMF_NORMAL);
iMenuMax = GetMenuItemCount(hmenuCtx);
wsprintf (szTrace, _T("Nb Items added to the menu %d\n\n"), iMenuMax);
TRACE (szTrace);
for (iMenuPos = 0 ; iMenuPos < iMenuMax; iMenuPos++)
{
GetMenuString(hmenuCtx, iMenuPos, szMenuItem, sizeof (szMenuItem), MF_BYPOSITION) ;
wsprintf (szTrace, _T("Menu Entry : %s\n"), szMenuItem);
TRACE (szTrace);
uiID = GetMenuItemID(hmenuCtx, iMenuPos) ;
if ((uiID == -1) || (uiID == 0))
{
wsprintf (szTrace, _T("No Verb found for the entry #%d \n\n"), uiID);
TRACE (szTrace);
}
else
{
hr = pCtxMenu->GetCommandString(uiID-1, GCS_VERBA, NULL, verb, sizeof (verb));
if (FAILED (hr))
{
verb[0] = TCHAR ('\0') ;
}
else
{
if (0 == _tcsicmp (verb, lpszCommand))
{
uiCommand = uiID-1 ;
}
}
wsprintf (szTrace, _T("verb %s (ret %d)\n\n"), verb, hr);
TRACE (szTrace);
}
}
if ((UINT)-1 != uiCommand)
{
CMINVOKECOMMANDINFO cmi;
ZeroMemory(&cmi, sizeof(CMINVOKECOMMANDINFO));
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = CMIC_MASK_FLAG_NO_UI;
cmi.hwnd = m_hWnd;
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.lpVerb = MAKEINTRESOURCE (uiCommand);
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = NULL;
cmi.hIcon = NULL;
hr = pCtxMenu->InvokeCommand(&cmi);
if (SUCCEEDED (hr))
{
bReturn = TRUE;
}
}
}
if(pCtxMenu!=NULL)
pCtxMenu->Release();
return bReturn;
}
作者: zwjuanster 发布时间: 2010-02-21
接分
回复内容太短了!
回复内容太短了!
作者: woheduole 发布时间: 2010-02-21
漏过
回复内容太短了!
回复内容太短了!
作者: haidejintou 发布时间: 2011-12-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28