Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;     
} 
Ejemplo n.º 3
0
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;
}               
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;     
}       
Ejemplo n.º 6
0
/// \brief Called by the shell when initializing a context menu or property sheet extension.
/// \param pIDFolder	Specifies the parent folder
/// \param pDataObj		Spefifies the set of items selected in that folder.
/// \param hRegKey		Specifies the type of the focused item in the selection.
/// \return						NOERROR in all cases.
/// Note that at the time this function is called, we don't know
/// (or care) what type of shell extension is being initialized.
/// It could be a context menu or a property sheet.\n
/// Extra: Implements the IShellExtInit member function necessary to support
/// the context menu and property sheet portioins of this shell extension.
STDMETHODIMP CContextMenu::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey)
{
	ODS("CContextMenu::Initialize()");

	// 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();
		
		STGMEDIUM medium;
		FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
		UINT uCount;

		if(SUCCEEDED(m_pDataObj->GetData(&fe, &medium)))
		{
			// Get the file name from the CF_HDROP.
			uCount = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0);
			if(uCount)
				DragQueryFile((HDROP)medium.hGlobal, 0, m_szFile, MAX_MATROSKA_PATH-2);

			ReleaseStgMedium(&medium);
		}
	}

	return NOERROR;
}
Ejemplo n.º 7
0
STDMETHODIMP DeskDropTarget::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;
            DragQueryFile(hDrop, 0, m_filename, sizeof(m_filename));
            DragFinish(hDrop);
            m_flags = is_stylefile(m_filename) ? 2 : 0;
        }
    }
    *pdwEffect = DROPEFFECT_NONE;
    return S_OK;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
void UDropTarget::FreeData()
{
    if(data) {
        data->Release();
        data = NULL;
    }
}
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;
}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) {
  HRESULT hres = 0;
  if (m_pDataObj)
    m_pDataObj->Release();
  if (pDataObj) {
    m_pDataObj = pDataObj;
    pDataObj->AddRef();
  }
  return NOERROR;
}
Ejemplo n.º 14
0
// *** IShellExtInit methods ***
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST /*pIDFolder*/, LPDATAOBJECT pDataObj, HKEY /*hRegKey*/) {
	if (m_pDataObj) {
		m_pDataObj->Release();
		m_pDataObj = NULL;
	}
	if (pDataObj) {
		m_pDataObj = pDataObj;
		pDataObj->AddRef();
	}
	return NOERROR;
}
Ejemplo n.º 15
0
//
//   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;
}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
STDMETHODIMP UDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
{
    GuiLock __;
    LLOG("DragEnter " << pt);
    data = pDataObj;
    data->AddRef();
    fmt.Clear();
    IEnumFORMATETC *fe;
    if(!ctrl || pDataObj->EnumFormatEtc(DATADIR_GET, &fe) != NOERROR) {
        *pdwEffect = DROPEFFECT_NONE;
        return NOERROR;
    }
    FORMATETC fmtetc;
    while(fe->Next(1, &fmtetc, 0) == S_OK) {
        fmt.FindAdd(FromWin32CF(fmtetc.cfFormat));
        if(fmtetc.ptd)
            CoTaskMemFree(fmtetc.ptd);
    }
    fe->Release();
    DnD(pt, false, pdwEffect, grfKeyState);
    return NOERROR;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
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;
}
Ejemplo n.º 20
0
// 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;
}
Ejemplo n.º 21
0
void COleServerItem::AddOtherClipboardData(COleDataSource* pDataSource)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDataSource);

	// get IEnumFORMATETC interface for the IDataObject
	LPDATAOBJECT lpDataObject = GetDataObject();
	LPENUMFORMATETC lpEnumFORMATETC;
	if (lpDataObject->EnumFormatEtc(DATADIR_GET, &lpEnumFORMATETC) != S_OK)
		return;
	ASSERT(lpEnumFORMATETC != NULL);

	// get all formats that the object will give us
	FORMATETC formatEtc;
	while (lpEnumFORMATETC->Next(1, &formatEtc, NULL) == S_OK)
	{
		STGMEDIUM stgMedium;
		if (lpDataObject->GetData(&formatEtc, &stgMedium) != S_OK)
		{
			// data is not available
			CoTaskMemFree(formatEtc.ptd);
		}
		else if (stgMedium.pUnkForRelease != NULL)
		{
			// don't cache data with pUnkForRelease != NULL
			::ReleaseStgMedium(&stgMedium);
			CoTaskMemFree(formatEtc.ptd);
		}
		else
		{
			// cache the data (now we own the stgMedium)
			pDataSource->CacheData(0, &stgMedium, &formatEtc);
		}
	}

	// cleanup
	lpEnumFORMATETC->Release();
}
Ejemplo n.º 22
0
// 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; 
} 
Ejemplo n.º 23
0
bool FTPWindow::AcceptType(LPDATAOBJECT pDataObj) {
	FORMATETC fmtetc;

	fmtetc.ptd	    = NULL;
	fmtetc.dwAspect = DVASPECT_CONTENT;
	fmtetc.lindex   = -1;
	fmtetc.tymed	= TYMED_HGLOBAL;
	fmtetc.cfFormat = CF_HDROP;

	if (pDataObj->QueryGetData(&fmtetc) == NOERROR)
		return true;

	return false;
}
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;
}
Ejemplo n.º 25
0
QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
QWindowsOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState,
                                 POINTL pt, LPDWORD pdwEffect)
{
    if (IDropTargetHelper* dh = QWindowsDrag::instance()->dropHelper())
        dh->DragEnter(reinterpret_cast<HWND>(m_window->winId()), pDataObj, reinterpret_cast<POINT*>(&pt), *pdwEffect);

    qCDebug(lcQpaMime) << __FUNCTION__ << "widget=" << m_window << " key=" << grfKeyState
        << "pt=" << pt.x << pt.y;

    QWindowsDrag::instance()->setDropDataObject(pDataObj);
    pDataObj->AddRef();
    const QPoint point = QWindowsGeometryHint::mapFromGlobal(m_window, QPoint(pt.x,pt.y));
    handleDrag(m_window, grfKeyState, point, pdwEffect);
    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;
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST  /* pIDFolder */,
				   LPDATAOBJECT pDataObj,
				   HKEY  /* hRegKey */)
{
    // 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();
    }

    return NOERROR;
}
Ejemplo n.º 29
0
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;
}
Ejemplo n.º 30
0
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;
}