FARINTERNAL UtGetIconData(LPDATAOBJECT lpSrcDataObj, REFCLSID rclsid, LPFORMATETC lpforetc, LPSTGMEDIUM lpstgmed) { VDATEHEAP(); CLSID clsid = rclsid; lpstgmed->tymed = TYMED_NULL; lpstgmed->pUnkForRelease = NULL; lpstgmed->hGlobal = NULL; if (lpSrcDataObj) { if (lpSrcDataObj->GetData(lpforetc, lpstgmed) == NOERROR) return NOERROR; if (IsEqualCLSID(clsid, CLSID_NULL)) UtGetClassID(lpSrcDataObj, &clsid); } // get data from registration database lpstgmed->hGlobal = OleGetIconOfClass(clsid, NULL, TRUE); if (lpstgmed->hGlobal == NULL) return ResultFromScode(E_OUTOFMEMORY); else lpstgmed->tymed = TYMED_MFPICT; return NOERROR; }
HRESULT FTPWindow::OnDrop(LPDATAOBJECT pDataObj, DWORD /*grfKeyState*/, POINTL /*pt*/, LPDWORD pdwEffect) { TreeView_Select(m_treeview.GetHWND(), NULL, TVGN_DROPHILITE); STGMEDIUM medium; FORMATETC formatetc; formatetc.cfFormat = CF_HDROP; formatetc.tymed = TYMED_HGLOBAL; formatetc.dwAspect = 0; formatetc.lindex = -1; formatetc.ptd = NULL;; HRESULT dataRes = pDataObj->GetData(&formatetc, &medium); if (dataRes == S_OK) { *pdwEffect = DROPEFFECT_COPY; HDROP hdrop = (HDROP)GlobalLock(medium.hGlobal); TCHAR pathToFile[MAX_PATH]; int filesDropped = DragQueryFile(hdrop, 0xffffffff, NULL, 0); for (int i = 0; i < filesDropped; ++i) { if (DragQueryFile(hdrop, i, pathToFile, MAX_PATH) != 0) { //pathToFile is not checked. If it doesnt exist or its a directory or link, CreateFile either allows a handle to be opened or not m_ftpSession->UploadFile(pathToFile, m_currentDropObject->GetPath(), true, 1); //1: User specified location } } GlobalUnlock(medium.hGlobal); GlobalFree(medium.hGlobal); } return S_OK; }
STDMETHODIMP CToolBarCombo::DragEnter(LPDATAOBJECT pDataObj , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect){ m_pIDataObject=NULL; ATL::CString sText; FORMATETC formatDetails; STGMEDIUM stmg; // Let's get the text from the "clipboard" formatDetails.cfFormat = CF_TEXT; formatDetails.dwAspect = DVASPECT_CONTENT; formatDetails.lindex = -1; formatDetails.ptd = NULL; formatDetails.tymed = TYMED_HGLOBAL; if (SUCCEEDED(pDataObj->GetData(&formatDetails, &stmg))) { sText = (LPSTR)GlobalLock(stmg.hGlobal); GlobalUnlock(stmg.hGlobal); if (stmg.hGlobal != NULL) ReleaseStgMedium(&stmg); } *pdwEffect=DROPEFFECT_COPY; m_pIDataObject=pDataObj; m_pIDataObject->AddRef(); return NOERROR; }
STDMETHODIMP CToolBarCombo::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect){ *pdwEffect=DROPEFFECT_NONE; if (m_pIDataObject == NULL) return E_FAIL; DragLeave(); FORMATETC formatDetails; STGMEDIUM stmg; // Let's get the text from the "clipboard" formatDetails.cfFormat = CF_TEXT; formatDetails.dwAspect = DVASPECT_CONTENT; formatDetails.lindex = -1; formatDetails.ptd = NULL; formatDetails.tymed = TYMED_HGLOBAL; if (SUCCEEDED(pDataObj->GetData(&formatDetails, &stmg))) { char* sClipboard = (char*)GlobalLock(stmg.hGlobal); ::SetWindowTextA(m_hWnd,sClipboard); AddtoHistory(sClipboard); GlobalUnlock(stmg.hGlobal); if (stmg.hGlobal != NULL) ReleaseStgMedium(&stmg); } *pdwEffect=DROPEFFECT_COPY; //search immediately after dragging ::PostMessage(GetParent(),kWM_TBCOMBOSEARCH_WEB, 0, 0); return NOERROR; }
STDMETHOD (DragEnter) (LPDATAOBJECT pDataObject, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect) { AddRef(); m_filename[0] = 0; if (pDataObject) { FORMATETC fmte; fmte.cfFormat = CF_HDROP; fmte.ptd = NULL; fmte.dwAspect = DVASPECT_CONTENT; fmte.lindex = -1; fmte.tymed = TYMED_HGLOBAL; STGMEDIUM medium; if (SUCCEEDED(pDataObject->GetData(&fmte, &medium))) { HDROP hDrop = (HDROP)medium.hGlobal; m_filename[0] = 0; DragQueryFile(hDrop, 0, m_filename, sizeof(m_filename)); DragFinish(hDrop); m_flags = is_stylefile(m_filename) ? 2 : 0; } } *pdwEffect = DROPEFFECT_NONE; return S_OK; }
HRESULT CShellMenu::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID) { if(NULL == lpdobj) { return E_INVALIDARG; } FORMATETC feFmtEtc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM mdmSTG = { TYMED_HGLOBAL }; if(FAILED(lpdobj->GetData(&feFmtEtc, &mdmSTG))) { return E_INVALIDARG; } HDROP hDrop = (HDROP)GlobalLock(mdmSTG.hGlobal); if(NULL == hDrop) { return E_INVALIDARG; } int nDropCount = ::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); if(nDropCount > 1) m_bMultiFile = true; else m_bMultiFile = false; if(nDropCount == 1) { ::DragQueryFile(hDrop, 0, m_FileName, MAX_PATH); } return S_OK; }
int readFromDataObject(LPDATAOBJECT lpDataObject, UINT fid, std::ostream& os, int* size, HWND hwnd) { FORMATETC format; format.cfFormat = static_cast<CLIPFORMAT> (fid); format.dwAspect = DVASPECT_CONTENT; format.ptd = 0; format.tymed = TYMED_HGLOBAL; format.lindex = -1; STGMEDIUM medium; ZeroMemory (&medium, sizeof (medium)); // Get the bitmap handle from the dropped IDataObject, // and then write it in the stream if (SUCCEEDED(lpDataObject->GetData(&format, &medium))) { if(medium.hGlobal != NULL) { os.write ((char *)&medium.hGlobal, sizeof(HANDLE)); os << std::ends; *size = sizeof(HANDLE) + 1; } } return (medium.hGlobal != NULL); }
STDMETHODIMP CEsteidShlExt::Initialize ( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; TCHAR szFile[MAX_PATH]; HRESULT hr = S_OK; m_Files.clear(); // Look for CF_HDROP data in the data object. if (FAILED(pDataObj->GetData(&fmt, &stg))) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. hDrop = (HDROP) GlobalLock(stg.hGlobal); // Make sure it worked. if (hDrop == NULL) { ReleaseStgMedium(&stg); return E_INVALIDARG; } // Sanity check - make sure there is at least one filename. UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); if (nFiles == 0) { GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return E_INVALIDARG; } for (UINT i = 0; i < nFiles; i++) { // Get path length in chars UINT len = DragQueryFile(hDrop, i, NULL, 0); if (len == 0 || len >= MAX_PATH) continue; // Get the name of the file if (DragQueryFile(hDrop, i, szFile, len+1) == 0) continue; tstring str = tstring(szFile); if (str.empty()) continue; m_Files.push_back(str); } if (m_Files.empty()) { // Don't show menu if no items were found hr = E_INVALIDARG; } GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return hr; }
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { HRESULT hres = E_FAIL; STGMEDIUM medium; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; // Initialize can be called more than once if (m_pDataObj) m_pDataObj->Release(); // duplicate the object pointer and registry handle if (pDataObj) { m_pDataObj = pDataObj; pDataObj->AddRef(); } // use the given IDataObject to get a list of filenames (CF_HDROP) hres = pDataObj->GetData(&fmte, &medium); if(FAILED(hres)) return E_FAIL; // find out how many files the user selected if(DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0) == 1) DragQueryFile((HDROP)medium.hGlobal, 0, m_szFile, sizeof(m_szFile)); ::ReleaseStgMedium(&medium); return NOERROR; }
STDMETHODIMP CShooterContextMenuExt::Initialize ( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { TCHAR szFile[MAX_PATH]; FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; // Look for CF_HDROP data in the data object. if ( FAILED( pDataObj->GetData ( &fmt, &stg ) )) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. hDrop = (HDROP) GlobalLock ( stg.hGlobal ); // Make sure it worked. if ( NULL == hDrop ) { ReleaseStgMedium ( &stg ); return E_INVALIDARG; } // Sanity check - make sure there is at least one filename. UINT uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 ); HRESULT hr = S_OK; if ( 0 == uNumFiles ) { GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return E_INVALIDARG; } // Get the name of the first file and store it in our member variable m_szFile. m_bHasDir = false; for(UINT uFile = 0 ; uFile < uNumFiles ; uFile++) { if(0 == DragQueryFile(hDrop, uFile, szFile, MAX_PATH)) continue; ATLTRACE("Checking file <%s>\n", szFile); m_fileList.push_back(szFile); if(IsDir(szFile)) m_bHasDir = true; } GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return hr; }
HRESULT STDMETHODCALLTYPE CHdrPropSheet::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpDatObj, HKEY hkeyProgID) { //OutputDebugString(_T("CHdrPropSheet::Initialize()\n")); if (lpDatObj == NULL) { return E_FAIL; } FORMATETC fmtetc; STGMEDIUM medium; fmtetc.cfFormat = CF_HDROP; fmtetc.ptd = NULL; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.lindex = -1; fmtetc.tymed = TYMED_HGLOBAL; if (FAILED(lpDatObj->GetData(&fmtetc, &medium))) { return E_FAIL; } HDROP hDrop = static_cast<HDROP>(medium.hGlobal); if (::DragQueryFile(hDrop, -1, NULL, 0) != 1) { // not multi files. ::ReleaseStgMedium(&medium); return E_FAIL; } ::DragQueryFile(hDrop, 0, m_szPath, lengthof(m_szPath)); ::ReleaseStgMedium(&medium); return CheckFileType(); }
HRESULT CSimpleShlExt::Initialize (LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { LPTSTR lpszBuffer; FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; UINT uNumFiles, i; // Look for CF_HDROP data in the data object. if (FAILED( pDataObj->GetData(&fmt, &stg) )) // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; // Get a pointer to the actual data. hDrop = (HDROP) GlobalLock ( stg.hGlobal ); // Make sure it worked. if (hDrop == NULL) return E_INVALIDARG; // Get the number of files selected // and make sure there is at least one file if ((uNumFiles = DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0 )) == 0) { GlobalUnlock( stg.hGlobal ); ReleaseStgMedium( &stg ); return E_INVALIDARG; } // Create buffer if (m_szFiles != NULL) delete [] m_szFiles; m_nFilesLength = 1; for (i=0; i<uNumFiles; ++i) m_nFilesLength += DragQueryFile(hDrop, i, NULL, 0) + 1; lpszBuffer = m_szFiles = new TCHAR[m_nFilesLength]; if (m_szFiles == NULL) { GlobalUnlock( stg.hGlobal ); ReleaseStgMedium( &stg ); return E_INVALIDARG; } // Append all files into the buffer seperated by '\0'. for (i=0; i<uNumFiles; ++i) { lpszBuffer += DragQueryFile(hDrop, i, lpszBuffer, MAX_PATH); *lpszBuffer++ = _T('\0'); } *lpszBuffer = _T('\0'); // End by a double '\0'. GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return S_OK; }
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { if (pDataObj == 0) { return E_INVALIDARG; } HRESULT hr = E_FAIL; FORMATETC format={CF_HDROP,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; STGMEDIUM medium; int i; TCHAR szDirectory[MAX_PATH]; TCHAR szAppData[MAX_PATH]; /*hr = */SHGetSpecialFolderPath(NULL, szAppData,CSIDL_COMMON_DESKTOPDIRECTORY ,FALSE); // Initialize can be called more than once if (m_pDataObj) m_pDataObj->Release(); // duplicate the object pointer and registry handle if (pDataObj) { m_pDataObj = pDataObj; pDataObj->AddRef(); } GatherAppData(); if (SUCCEEDED(pDataObj->GetData(&format,&medium))) { HDROP hDrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if (hDrop) { m_nSelected=DragQueryFile((HDROP&)medium.hGlobal,0xFFFFFFFF,NULL,0); for(i=0;i<m_nSelected;i++) { DragQueryFile((HDROP&)medium.hGlobal,i,szDirectory,MAX_PATH); if(i==0) { _tcscpy(m_szCommand,szDirectory); _tcscat(m_szCommand,_T("*")); } else { _tcscat(m_szCommand,szDirectory); _tcscat(m_szCommand,_T("*")); } hr = S_OK; } GlobalUnlock(medium.hGlobal); } } return hr; }
// // FUNCTION: CDrmShlExt::Initialize(LPCITEMIDLIST, LPDATAOBJECT, // HKEY) // // PURPOSE: Initializes the context menu extension. // IFACEMETHODIMP CDrmShlExt::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID) { HRESULT hr = E_INVALIDARG; if (NULL == pDataObj) { return hr; } FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stm; // pDataObj contains the objects being acted upon. In this project, // we get an HDROP handle for enumerating the selected files. if (SUCCEEDED(pDataObj->GetData(&fe, &stm))) { // Get an HDROP handle. HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal)); if (hDrop != NULL) { // Determine how many files are involved in this operation. UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); if (nFiles != 0) { // Get the name of the first file. if (0 != DragQueryFile(hDrop, 0, m_szFileName, MAX_PATH)) { hr = S_OK; } // [-or-] //store the list of filenames in our list wchar_t tmpFile[MAX_PATH]; //temporary string to hold a file for(UINT i = 0; i < nFiles; i++) { if (0 == DragQueryFile(hDrop, i, tmpFile, MAX_PATH)) hr = E_INVALIDARG; else this->fileList.push_front(tmpFile); } //hr = S_OK; } GlobalUnlock(stm.hGlobal); } ReleaseStgMedium(&stm); } // If any value other than S_OK is returned from the method, the context // menu is not displayed. return hr; }
STDMETHODIMP CDeskBand::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY /* hRegKey */) { m_ContextItems.clear(); m_ContextDirectory.clear(); // get selected files/folders if (pDataObj) { STGMEDIUM medium; FORMATETC fmte = {(CLIPFORMAT)g_shellidlist, (DVTARGETDEVICE FAR *)NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; HRESULT hres = pDataObj->GetData(&fmte, &medium); if (SUCCEEDED(hres) && medium.hGlobal) { //Enumerate PIDLs which the user has selected CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal); ItemIDList parent( GetPIDLFolder (cida)); int count = cida->cidl; for (int i = 0; i < count; ++i) { ItemIDList child (GetPIDLItem (cida, i), &parent); tstring str = child.toString(); if (str.empty() == false) { m_ContextItems[str] = ENABLED_VIEWPATH|ENABLED_FOLDERSELECTED|ENABLED_FILESELECTED; } } GlobalUnlock(medium.hGlobal); ReleaseStgMedium ( &medium ); if (medium.pUnkForRelease) { IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease; relInterface->Release(); } } } // get folder background if (pIDFolder) { ItemIDList list(pIDFolder); m_ContextDirectory = list.toString(); } return NOERROR; }
String UDropTarget::Get(const char *fmt) const { FORMATETC fmtetc = ToFORMATETC(fmt); STGMEDIUM s; if(data->GetData(&fmtetc, &s) == S_OK && s.tymed == TYMED_HGLOBAL) { char *val = (char *)GlobalLock(s.hGlobal); String data(val, (int)GlobalSize(s.hGlobal)); GlobalUnlock(s.hGlobal); ReleaseStgMedium(&s); return data; } return Null; }
// Initialize the context menu handler. IFACEMETHODIMP FileContextMenuExt::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID) { if (NULL == pDataObj) { return E_INVALIDARG; } HRESULT hr = E_FAIL; FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stm; // The pDataObj pointer contains the objects being acted upon. In this // example, we get an HDROP handle for enumerating the selected files and // folders. if (SUCCEEDED(pDataObj->GetData(&fe, &stm))) { // Get an HDROP handle. HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal)); if (hDrop != NULL) { // Determine how many files are involved in this operation. This // code sample displays the custom context menu item when only // one file is selected. UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); wchar_t szSelectedFile[MAX_PATH]; for (UINT count = 0; count < nFiles;count++) { // Get the path of the file. if (0 == DragQueryFile(hDrop, count,szSelectedFile, ARRAYSIZE(szSelectedFile))) { continue; } names.push_back(szSelectedFile); hr = S_OK; } GlobalUnlock(stm.hGlobal); } ReleaseStgMedium(&stm); } // If any value other than S_OK is returned from the method, the context // menu item is not displayed. return hr; }
HRESULT CPNExt::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; TCHAR szFile[MAX_PATH+1]; m_files.clear(); // Look for CF_HDROP data in the data object. if( FAILED( pDataObj->GetData ( &fmt, &stg )) ) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. hDrop = (HDROP) ::GlobalLock( stg.hGlobal ); // Make sure it worked. if ( NULL == hDrop ) { ::ReleaseStgMedium( &stg ); return E_INVALIDARG; } // Sanity check – make sure there is at least one filename. UINT uNumFiles = ::DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0 ); if ( 0 == uNumFiles ) { ::GlobalUnlock ( stg.hGlobal ); ::ReleaseStgMedium ( &stg ); return E_INVALIDARG; } // Get all the filenames... for( UINT uFile = 0; uFile < uNumFiles; uFile++ ) { // Get the next filename. if ( 0 == ::DragQueryFile( hDrop, uFile, szFile, MAX_PATH )) continue; m_files.push_back( tstring(szFile) ); } ::GlobalUnlock ( stg.hGlobal ); ::ReleaseStgMedium ( &stg ); return ( m_files.size() > 0 ) ? S_OK : E_INVALIDARG; }
// CSimpleShlExt //我们要做的是取得被右击选择的文件名,再把该文件名显示在弹出消息框中。 //可能会有多个文件同时被选择右击, 你可以用pDataObj 接口指针获取所有的文件名, 但现在为简单起见, 我们只获取第一个文件名. //add by ray 2014-05-15 17:45 HRESULT CSimpleShlExt::Initialize ( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { //文件名的存放格式与你拖放文件到带WS_EX_ACCEPTFILES风格的窗口时使用的文件名格式是一样的。 // 这就是说我们可以使用同样的API来获取文件名: DragQueryFile(). // 首先我们先获取包含在IdataObject中的数据句柄: FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; // 在数据对象内查找 CF_HDROP 型数据. if ( FAILED( pDataObj->GetData ( &fmt, &stg ))) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // 获得指向实际数据的指针 hDrop = (HDROP) GlobalLock ( stg.hGlobal ); // 检查非NULL. if ( NULL == hDrop ) { return E_INVALIDARG; } //请注意错误检查,特别是指针的检查。 // 由于我们的扩展运行在 Explorer 进程内, 要是我们的代码崩溃了, Explorer也会随之崩溃. 在Win 9x上, 这样的一个崩溃可能导致需要重启系统. // 所以, 现在我们有了一个 HDROP 句柄, 我们就可以获取我们需要的文件名了: // 有效性检查 – 保证最少有一个文件名. UINT uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 ); if ( 0 == uNumFiles ) { GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return E_INVALIDARG; } HRESULT hr = S_OK; // 取得第一个文件名并把它保存在类成员m_szFile 中. if ( 0 == DragQueryFile ( hDrop, 0, m_szFile, MAX_PATH )) { hr = E_INVALIDARG; } GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return hr; }
IFACEMETHODIMP LiferayNativityContextMenus::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID) { if (NULL == pDataObj) { return E_INVALIDARG; } HRESULT hr = E_FAIL; FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stm; if (!SUCCEEDED(pDataObj->GetData(&fe, &stm))) { return E_FAIL; } HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal)); if (hDrop == NULL) { return E_FAIL; } _nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); if (_nFiles > 0) { _contextMenuUtil = new ContextMenuUtil(); wchar_t szFileName[MAX_PATH]; for (UINT i = 0; i < _nFiles; i++) { UINT success = DragQueryFile(hDrop, i, szFileName, ARRAYSIZE(szFileName)); if (success != 0) { _contextMenuUtil->AddFile(szFileName); } } } GlobalUnlock(stm.hGlobal); ReleaseStgMedium(&stm); return S_OK; }
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { FORMATETC format={CF_HDROP,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; STGMEDIUM medium; int i,nLen; WCHAR szDirectory[MAX_PATH]; HRESULT hr; TCHAR szAppData[MAX_PATH]; hr = SHGetSpecialFolderPath(NULL, szAppData,CSIDL_COMMON_DESKTOPDIRECTORY ,FALSE); // Initialize can be called more than once if (m_pDataObj) m_pDataObj->Release(); // duplicate the object pointer and registry handle if (pDataObj) { m_pDataObj = pDataObj; pDataObj->AddRef(); } pDataObj->GetData(&format,&medium); m_nSelected=DragQueryFileW((HDROP&)medium.hGlobal,0xFFFFFFFF,NULL,0); if (m_nSelected == -1 || m_nSelected ==0) { wcscpy(m_szCommand,L"DeleteFileInRecycled"); return NOERROR; } m_szCommand[0] = L'\0'; for(i=0;i<m_nSelected;i++) { DragQueryFileW((HDROP&)medium.hGlobal,i,szDirectory,MAX_PATH); if (i != 0) wcscat(m_szCommand,L" "); nLen = wcslen(m_szCommand); m_szCommand[nLen] = L'"'; m_szCommand[nLen+1] = L'\0'; wcscat(m_szCommand,szDirectory); nLen = wcslen(m_szCommand); m_szCommand[nLen] = L'"'; m_szCommand[nLen+1] = L'\0'; } return NOERROR; }
STDMETHODIMP CShellExtension::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; // Look for CF_HDROP data in the data object. if (FAILED(pDataObj->GetData(&fmt, &stg))) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. hDrop = (HDROP)GlobalLock(stg.hGlobal); // Make sure it worked. if (NULL == hDrop) return E_INVALIDARG; // Sanity check - make sure there is at least one filename. UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); HRESULT hr = S_OK; if (0 == uNumFiles) { GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return E_INVALIDARG; } m_numFiles = uNumFiles; TCHAR opString[MAX_PATH]; _stprintf_s(opString, MAX_PATH, TEXT("Found %d files"), uNumFiles); OutputDebugString(opString); // Get the name of the first file and store it in our member variable m_szFile. if (0 == DragQueryFile(hDrop, 0, m_szFile, MAX_PATH)) hr = E_INVALIDARG; GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return hr; }
STDMETHODIMP CGitExtensionsShellEx::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; /* store the folder, if provided */ DBG_TRACE(L"CGitExtensionsShellEx::Initialize(pidlFolder=%p)", pidlFolder); m_szFile[0] = '\0'; if (pidlFolder) SHGetPathFromIDList(pidlFolder, m_szFile); if (!pDataObj) return S_OK; // Look for CF_HDROP data in the data object. if (FAILED( pDataObj->GetData(&fmt, &stg))) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. hDrop = (HDROP)GlobalLock(stg.hGlobal); // Make sure it worked. if (NULL == hDrop) return E_INVALIDARG; // Sanity check - make sure there is at least one filename. UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); HRESULT hr = S_OK; DBG_TRACE(L"uNumFiles=%u", uNumFiles); if (uNumFiles != 1) hr = E_INVALIDARG; // Get the name of the first file and store it in our member variable m_szFile. else if (!DragQueryFile(hDrop, 0, m_szFile, MAX_PATH)) hr = E_INVALIDARG; DBG_TRACE(L"m_szFile=%s", m_szFile); GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return hr; }
STDMETHODIMP ExifShellExtension::Initialize( LPCITEMIDLIST /*pidlFolder*/, LPDATAOBJECT pDataObj, HKEY /*hProgID*/) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; // Look for CF_HDROP data in the data object. if (FAILED(pDataObj->GetData(&fmt, &stg))) { // Nope! Return an "invalid argument" error back to Explorer. return E_INVALIDARG; } // Get a pointer to the actual data. HDROP hDrop = (HDROP) GlobalLock(stg.hGlobal); // Make sure it worked. if (NULL == hDrop) return E_INVALIDARG; // Sanity check - make sure there is at least one filename. UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); HRESULT hr = S_OK; if (1 != uNumFiles) { GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return E_INVALIDARG; } // Get the name of the file and store it TCHAR szFile[MAX_PATH]; UINT u = 0; if (0 == DragQueryFile(hDrop, u, szFile, MAX_PATH)) hr = E_INVALIDARG; else m_cszFilename = szFile; GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return hr; }
HRESULT CZipContextMenu::GetFileNames(LPDATAOBJECT dataObject, UStringVector &fileNames) { fileNames.Clear(); if(dataObject == NULL) return E_FAIL; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; NCOM::CStgMedium stgMedium; HRESULT result = dataObject->GetData(&fmte, &stgMedium); if (result != S_OK) return result; stgMedium._mustBeReleased = true; NShell::CDrop drop(false); NMemory::CGlobalLock globalLock(stgMedium->hGlobal); drop.Attach((HDROP)globalLock.GetPointer()); drop.QueryFileNames(fileNames); return S_OK; }
// IShellExtInit::Initialize HRESULT CCopyPathExt::Initialize(LPCITEMIDLIST /*pidlFolder*/, LPDATAOBJECT lpdobj, HKEY /*hKeyProgID*/) { try { if ( lpdobj == NULL ) return E_INVALIDARG; // Get the data as CF_HDROP STGMEDIUM medium; FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; HRESULT hr = lpdobj->GetData( &fe, &medium ); if ( FAILED( hr ) ) return E_INVALIDARG; // Get the number of selected files //得到选择文件数量 m_cFiles = DragQueryFile( reinterpret_cast<HDROP>(medium.hGlobal), 0xFFFFFFFF, NULL, NULL ); // Build the list of file names m_lstFiles.clear(); for ( int iFile = 0; iFile < m_cFiles; iFile++ ) { //得到选择文件名 // Get the name of the selected file memset( m_szFile, 0, sizeof m_szFile ); DragQueryFile( reinterpret_cast<HDROP>(medium.hGlobal), iFile, m_szFile, sizeof(m_szFile)/sizeof(m_szFile[0]) ); m_lstFiles.push_back( m_szFile ); } //释放菜单 ReleaseStgMedium(&medium); return hr; } catch ( ... ) { return E_FAIL; } };
// IShellExtInit STDMETHODIMP CWorkshareMenu::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID) { if (lpdobj == NULL) return E_INVALIDARG; // The file can be referenced through the STGMEDIUM structure // that is retrievable through the IDataObject pointer, and // DragQueryFile can then be used to retrieve the file name. STGMEDIUM medium; FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; if(FAILED(lpdobj->GetData(&fe, &medium))) return E_INVALIDARG; CollectFilenames(reinterpret_cast<HDROP>(medium.hGlobal)); ReleaseStgMedium(&medium); return S_OK; }
STDMETHODIMP CExRichEditWindowless::QueryAcceptData(LPDATAOBJECT lpdataobj, CLIPFORMAT FAR *lpcfFormat,DWORD reco, BOOL fReally, HGLOBAL hMetaPict) { if ( NULL == lpdataobj ) return E_INVALIDARG; HRESULT hr; FORMATETC formatEtc; STGMEDIUM stgMedium; UINT uFormat = m_uOwnOleClipboardFormat; if (0 == uFormat) { return E_FAIL; } SecureZeroMemory(&formatEtc, sizeof(FORMATETC)); formatEtc.cfFormat = uFormat; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.ptd = NULL; formatEtc.tymed = TYMED_HGLOBAL; hr = lpdataobj->GetData(&formatEtc, &stgMedium); if (S_OK == hr) { LPTSTR pDest = LPTSTR(::GlobalLock(stgMedium.hGlobal)); if (pDest != NULL) { ReplaceSel(CString(pDest),true); ::GlobalUnlock(stgMedium.hGlobal); ::ReleaseStgMedium( &stgMedium ); return S_OK; } else { ::ReleaseStgMedium( &stgMedium ); return E_FAIL; } } return S_OK; }
STDMETHODIMP CHashCheck::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pdtobj, HKEY hkeyProgID ) { // We'll be needing a buffer, and let's double it just to be safe TCHAR szPath[MAX_PATH << 1]; // Make sure that we are working with a fresh list SLRelease(m_hList); m_hList = SLCreate(); // This indent exists to facilitate diffing against the CmdOpen source { FORMATETC format = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM medium; if (!pdtobj || pdtobj->GetData(&format, &medium) != S_OK) return(E_INVALIDARG); if (HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal)) { UINT uDrops = DragQueryFile(hDrop, -1, NULL, 0); for (UINT uDrop = 0; uDrop < uDrops; ++uDrop) { if (DragQueryFile(hDrop, uDrop, szPath, countof(szPath))) { SLAddStringI(m_hList, szPath); } } GlobalUnlock(medium.hGlobal); } ReleaseStgMedium(&medium); } // If there was any failure, the list would be empty... return((SLCheck(m_hList)) ? S_OK : E_INVALIDARG); }
STDMETHODIMP CContextMenuExt::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID ) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; // Look for CF_HDROP data in the data object. If there is no such data, return an error back to Explorer. if ( FAILED( pDataObj->GetData ( &fmt, &stg ) )) return E_INVALIDARG; // Get a pointer to the actual data. hDrop = (HDROP) GlobalLock ( stg.hGlobal ); // Make sure it worked. if ( NULL == hDrop ) return E_INVALIDARG; // Sanity check, make sure there is at least one filename. UINT uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 ); HRESULT hr = S_OK; if ( 0 == uNumFiles ) { GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return E_INVALIDARG; } // Get the name of the first file and store it in our member variable m_szFile. if ( 0 == DragQueryFile ( hDrop, 0, m_szFile, MAX_PATH ) ) hr = E_INVALIDARG; GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); return hr; }