1 #include "ContextMenu.h"
\r
2 #include "resource.h"
\r
4 #define EXEPATH L"CompleteEraser.EXE"
\r
6 HANDLE CContextMenu::m_hMapping;
\r
8 CContextMenu::CContextMenu()
\r
12 WCHAR wszLocale[MAX_PATH];
\r
13 GetLocaleInfoW(GetThreadLocale(),
\r
14 LOCALE_SABBREVLANGNAME,wszLocale,MAX_PATH);
\r
15 _wsetlocale(LC_ALL,wszLocale);
\r
20 CContextMenu::~CContextMenu()
\r
25 STDMETHODIMP_(ULONG) CContextMenu::AddRef()
\r
27 return InterlockedIncrement(&m_cRef);
\r
30 STDMETHODIMP_(ULONG) CContextMenu::Release()
\r
32 if (InterlockedDecrement(&m_cRef) == 0) {
\r
40 STDMETHODIMP CContextMenu::QueryInterface(REFIID riid, void **ppvObject)
\r
44 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IContextMenu))
\r
45 *ppvObject = static_cast<IContextMenu *>(this);
\r
46 else if (IsEqualIID(riid, IID_IShellExtInit))
\r
47 *ppvObject = static_cast<IShellExtInit *>(this);
\r
49 return E_NOINTERFACE;
\r
56 STDMETHODIMP CContextMenu::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
\r
60 ::RegQueryValueEx(hkeyProgID,L"",NULL,NULL,NULL,&size);
\r
61 temp = new WCHAR[size];
\r
62 ::RegQueryValueEx(hkeyProgID,L"",NULL,NULL,(LPBYTE)temp,&size);
\r
63 std::wstring value(temp);
\r
65 if(value == L"Recycle Bin")
\r
67 menutype = ClearRecyleBin;
\r
71 FORMATETC fetc = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
74 HRESULT hr = pdtobj->GetData(&fetc, &medium);
\r
78 HDROP DropData = (HDROP)GlobalLock(medium.hGlobal); //
\83\8d\83b
\83N
\82µ
\82È
\82¢
\82Æ
\97\8e\82¿
\82é
\82±
\82Æ
\82ª
\82 \82é
\r
80 UINT count = DragQueryFile(DropData,0xFFFFFFFF,NULL,0);
\r
82 for(UINT i = 0; i < count; i++)
\r
84 WCHAR file[_MAX_PATH];
\r
85 DragQueryFile((HDROP)medium.hGlobal, i, file, sizeof(file));
\r
86 this->strs.append(file);
\r
87 this->strs.append(L"\n");
\r
90 GlobalUnlock(DropData);
\r
92 ReleaseStgMedium(&medium);
\r
94 menutype = ClearFileNames;
\r
99 STDMETHODIMP CContextMenu::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
\r
103 if (uFlags & CMF_DEFAULTONLY)
\r
104 return MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_NULL, 0);
\r
106 mii.cbSize = sizeof(MENUITEMINFO);
\r
107 mii.fMask = MIIM_ID | MIIM_TYPE;
\r
108 mii.fType = MFT_STRING;
\r
109 mii.wID = idCmdFirst;
\r
111 if(menutype == ClearFileNames)
\r
114 MyLoadString(str,MENUITEMNAME);
\r
115 mii.dwTypeData = const_cast<LPWSTR>(str.c_str());
\r
116 InsertMenuItem(hmenu, indexMenu, TRUE, &mii);
\r
117 }else if(menutype == ClearRecyleBin){
\r
119 MyLoadString(str,MENUITEMNAME_RECYLEBIN);
\r
120 mii.dwTypeData = const_cast<LPWSTR>(str.c_str());
\r
122 SHQUERYRBINFO sqrbi;
\r
123 ZeroMemory(&sqrbi, sizeof(sqrbi));
\r
124 sqrbi.cbSize = sizeof(sqrbi);
\r
125 if(SUCCEEDED(SHQueryRecycleBin(NULL, &sqrbi)))
\r
127 mii.fState |= (sqrbi.i64NumItems != 0) ? MFS_ENABLED : MFS_DISABLED;
\r
130 InsertMenuItem(hmenu, indexMenu, TRUE, &mii);
\r
133 return MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_NULL, 2);
\r
136 STDMETHODIMP CContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
\r
138 UINT idCmd = LOWORD(pici->lpVerb);
\r
140 if (HIWORD(pici->lpVerb) != 0)
\r
141 return E_INVALIDARG;
\r
147 MyLoadString(str,CONFIRMDELETE);
\r
148 if(MessageBoxW(NULL,str.c_str(),NULL,MB_YESNO) == IDNO)
\r
151 if (menutype == ClearFileNames)
\r
153 UINT mapSize = this->strs.length() * sizeof(wchar_t);
\r
155 m_hMapping = ::CreateFileMappingW(INVALID_HANDLE_VALUE,
\r
160 L"CompleteEraser.MemMap");
\r
161 if(m_hMapping == NULL)
\r
164 void *m_pMappingView = MapViewOfFile(m_hMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
\r
165 if(m_pMappingView == NULL)
\r
168 ::wcscat_s((LPWSTR)m_pMappingView,mapSize,this->strs.c_str());
\r
170 UnmapViewOfFile(m_pMappingView);
\r
173 CreateThread(NULL , 0 , ThreadFunc , (LPVOID)this , 0 , &dwID);
\r
175 else if (menutype == ClearRecyleBin)
\r
177 RunCompleteEraer(L"/recylebin");
\r
183 STDMETHODIMP CContextMenu::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax)
\r
187 if (uFlags == GCS_HELPTEXTW)
\r
189 MyLoadString(str,MENUHELPMSG);
\r
190 ::wcscpy_s((LPWSTR)pszName,cchMax,str.c_str());
\r
192 else if (uFlags == GCS_VERBW)
\r
194 MyLoadString(str,MENUITEMNAME);
\r
195 ::wcscpy_s((LPWSTR)pszName,cchMax,str.c_str());
\r
204 DWORD WINAPI CContextMenu::ThreadFunc(LPVOID pParam)
\r
206 HANDLE hProcess = RunCompleteEraer(L"");
\r
208 WaitForSingleObject(hProcess,INFINITE);
\r
210 CloseHandle(m_hMapping);
\r
215 HANDLE CContextMenu::RunCompleteEraer(LPTSTR cmdline)
\r
217 WCHAR modPath[_MAX_PATH];
\r
218 GetModulePath(modPath,_MAX_PATH);
\r
220 SHELLEXECUTEINFO info = {0};
\r
221 info.cbSize = sizeof(info);
\r
223 info.nShow = SW_SHOWNORMAL;
\r
224 info.fMask = SEE_MASK_NOCLOSEPROCESS;
\r
225 info.lpDirectory = modPath;
\r
226 info.lpFile = EXEPATH;
\r
227 info.lpParameters = cmdline;
\r
228 ShellExecuteEx(&info);
\r
230 return info.hProcess;
\r