/// \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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
STDMETHODIMP 
CShellExt::Initialize(
	LPCITEMIDLIST	pIDFolder, 
	LPDATAOBJECT	pDataObj, 
	HKEY			hRegKey)
{
	DualErr derr;

	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// Initialize can be called more than once.
	if (mPDataObj)
		mPDataObj->Release();

	// Duplicate the object pointer and registry handle, and extract the path
	// of the file or drive being operated on.

	if (NULL!=(int)(pDataObj))
	{
		mPDataObj = pDataObj;
		pDataObj->AddRef();

		derr = PreparePathsAndCommandLine();
	}

	if (derr.IsntError())
		return NOERROR;
	else
		return E_OUTOFMEMORY;
}
Esempio n. 4
0
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;
}
Esempio n. 5
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;
}
Esempio n. 6
0
LPDATAOBJECT COleDataObject::GetIDataObject(BOOL bAddRef)
{
	EnsureClipboardObject();

	LPDATAOBJECT lpDataObject = m_lpDataObject;
	if (bAddRef && lpDataObject != NULL)
		lpDataObject->AddRef();

	return lpDataObject;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 10
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;
}
Esempio n. 11
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;
}
Esempio n. 12
0
STDMETHODIMP CLocateShellExtension::Initialize(LPCITEMIDLIST pIDFolder,
                                   LPDATAOBJECT pDataObj,
                                   HKEY hRegKey)
{
	DebugFormatMessage("CLocateShellExtension::Initialize(%X,%X,%X)",pIDFolder,pDataObj,hRegKey);

	if (pDataObj==NULL)
		return E_INVALIDARG;

	FORMATETC FormatEtc;
	STGMEDIUM med;
	FormatEtc.cfFormat=RegisterClipboardFormat(CFSTR_SHELLIDLIST);
	FormatEtc.ptd=NULL;
	FormatEtc.dwAspect=DVASPECT_CONTENT;
	FormatEtc.lindex=-1;
    FormatEtc.tymed=TYMED_HGLOBAL;
	
	if (pDataObj->GetData(&FormatEtc,&med)==S_OK)
	{
		// May be computer?
		IShellFolder *psf;
		if (!SUCCEEDED(SHGetDesktopFolder(&psf)))
		{
			DebugMessage("No IShellFolder interface");
			return E_FAIL;
		}
		
		// Retrieving data from item id list
		BYTE* pData=(BYTE*)GlobalLock(med.hGlobal);
		
		UINT nFiles=((int*)pData)[0];
		UINT i,nLines=1,nSubIDListLen,nIDListLen;
		WCHAR szPath[_MAX_PATH];

		nSubIDListLen=GetIDListSize((LPITEMIDLIST)(pData+((int*)pData)[1]))-2;
		
		for (i=0;i<nFiles;i++)
		{
			nIDListLen=GetIDListSize((LPITEMIDLIST)(pData+((int*)pData)[2+i]));

			// Constructing IDList from parent item and item
            LPITEMIDLIST pItemIDList=(LPITEMIDLIST)new BYTE[nSubIDListLen+nIDListLen+2];
			CopyMemory((BYTE*)pItemIDList,(LPCSTR)(pData+((int*)pData)[1]),nSubIDListLen);
			CopyMemory((BYTE*)(pItemIDList)+nSubIDListLen,(LPCSTR)(pData+((int*)pData)[2+i]),nIDListLen);
			
			if (SHGetPathFromIDListW(pItemIDList,szPath))
			{
				DebugFormatMessage(L"SHGetPathFromIDListW gives %s",szPath);

				if (IsDirectory(szPath))
				{
					WCHAR szTarget[MAX_PATH];
					switch (GetNethoodTarget(szPath,szTarget,MAX_PATH))
					{
					case 1:
						m_aComputers.Add(alloccopy(szTarget));
						break;
					case 2:
						m_aDirectories.Add(alloccopy(szTarget));
						break;
					case 0:
						m_aDirectories.Add(alloccopy(szPath));
						break;
					}
				}
				else
					m_aFiles.Add(alloccopy(szPath));
			}
			else
			{
				DebugHexDump("idlist",(BYTE*)pItemIDList,nSubIDListLen+nIDListLen);
				
				STRRET str;
				if (SUCCEEDED(psf->GetDisplayNameOf(pItemIDList,SHGDN_NORMAL|SHGDN_FORPARSING,&str)))
				{
					if (SUCCEEDED(StrRetToBufW(&str,pItemIDList,szPath,MAX_PATH)))
					{
						if (szPath[0]!='\\' && szPath[1]!='\\')
							DebugFormatMessage("Cannot add item %s",szPath);
						else
							m_aComputers.Add(alloccopy(szPath));
					}
					else
						DebugMessage("StrRetToStr failed");
				}
				else
					DebugMessage("GetDisplayNameOf failed");

			}
			
			delete[] (BYTE*)pItemIDList;
		}
		
		GlobalUnlock(med.hGlobal);
		if (med.pUnkForRelease==NULL)
            GlobalFree(med.hGlobal);
		else 
			med.pUnkForRelease->Release();
	
		psf->Release();
	}
	else 
	{
		FormatEtc.cfFormat=CF_HDROP;
		if (m_pDataObj->GetData(&FormatEtc,&med)==S_OK)
		{
			LPDROPFILES df=(LPDROPFILES)GlobalLock(med.hGlobal);
			if (df->fWide)
			{
				LPWSTR lpPtr=(LPWSTR)((BYTE*)df+df->pFiles);
				SIZE_T nLen;
				while (nLen=wcslen(lpPtr))
				{
					DebugFormatMessage(L"HDROP contains file %s",(LPCSTR)(lpPtr));
					if (IsDirectory(lpPtr))
					{
						WCHAR szTarget[MAX_PATH];
						switch (GetNethoodTarget(lpPtr,szTarget,MAX_PATH))
						{
						case 1:
							m_aComputers.Add(alloccopy(szTarget));
							break;
						case 2:
							m_aDirectories.Add(alloccopy(szTarget));
							break;
						case 0:
							m_aDirectories.Add(alloccopy(lpPtr,nLen));
							break;
						}
					}
					else
						m_aFiles.Add(alloccopy(lpPtr,nLen));
					
					lpPtr+=nLen+1;
				}
			}
			else
			{
				LPSTR lpPtr=(LPSTR)df+df->pFiles;
				SIZE_T nLen;
				while (nLen=strlen(lpPtr))
				{
					LPWSTR lpFile=alloccopyAtoW(lpPtr,nLen);					

					if (IsDirectory(lpFile))
						m_aDirectories.Add(lpFile);
					else
						m_aFiles.Add(lpFile);

					lpPtr+=nLen+1;
				}
			}	
			
			GlobalUnlock(med.hGlobal);
			
			if (med.pUnkForRelease==NULL)
                GlobalFree(med.hGlobal);
			else 
				med.pUnkForRelease->Release();
		}
	}

	
    // 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;
}