Platform SDK Shell >> Drag/Drop from Filesystem

by Bill Rowell » Wed, 01 Jun 2005 01:41:44 GMT

Is there a way to get the name (or path) of the source folder when a
drag/drop is initiated from the file system? What

I mean by this is I want the name of the source folder when I drag/drop
items from the file system into my NSE.

Thanks!

-Bill





Platform SDK Shell >> Drag/Drop from Filesystem

by Michael Phillips, Jr. » Wed, 01 Jun 2005 01:56:34 GMT


If you have IContextMenu implemented with the IShellExtInit interface,
the IShellExtInit::Initialize gets called with the source and destination
of the items dragged.









Platform SDK Shell >> Drag/Drop from Filesystem

by Bill Rowell » Thu, 02 Jun 2005 03:22:11 GMT

From reading about IShellExtInit on MSDN, the arguments to Initialize are:

pidlFolder - For nondefault drag-and-drop menu extensions, specifies the
target folder
pdtobj - specifies the objects being acted upon
hkeyProgID - registry key for the file object or folder type

So it doesn't seem as this would be of much use...nevermind the fact that
though it is implemented in my IContextMenu implementation, it never gets
called from what I can tell.









Drag/Drop from Filesystem

by S2FsbGlNYW4 » Thu, 02 Jun 2005 04:04:02 GMT

try with this:

STDMETHODIMP CContextMenu::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT
lpdobj, HKEY hkeyProgID)
{
DWORD dwErrcode = 0L;
FORMATETC fe;
STGMEDIUM stgmed;

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

// Get the storage medium from the data object.
HRESULT hr = lpdobj->GetData(&fe, &stgmed);
m_arrFileNames.RemoveAll();
if (SUCCEEDED(hr))
{
if(stgmed.hGlobal)
{
int iSize = 0;
LPDROPFILES pDropFiles = (LPDROPFILES)GlobalLock(stgmed.hGlobal);

LPTSTR pszFiles = NULL, pszTemp = NULL;
LPWSTR pswFiles = NULL, pswTemp = NULL;

if (pDropFiles->fWide)
{
pswFiles = (LPWSTR) ((BYTE*) pDropFiles + pDropFiles->pFiles);
pswTemp = (LPWSTR) ((BYTE*) pDropFiles + pDropFiles->pFiles);
m_arrFileNames.Add(_bstr_t(pswFiles));
}
else
{
pszFiles = (LPTSTR) pDropFiles + pDropFiles->pFiles;
pszTemp = (LPTSTR) pDropFiles + pDropFiles->pFiles;
m_arrFileNames.Add(pszFiles);
}
}
GlobalUnlock(stgmed.hGlobal);
ReleaseStgMedium(&stgmed);
}
else
dwErrcode = GetLastError();

return NOERROR;
}


Drag/Drop from Filesystem

by Bill Rowell » Thu, 02 Jun 2005 05:19:27 GMT

I think that gets the list of files you're dragging, not the folder you're
dragging them from.

I've already implemented that in my implementation of IDropTarget.







Drag/Drop from Filesystem

by Michael Phillips, Jr. » Thu, 02 Jun 2005 07:12:01 GMT

IShellView::GetItemObject( SVGIO_SELECTION...
will give you the IDataobject for the item that your selected .

This item can be a file, a folder or a combination of the two.

IContextMenu with IShellExtInit::Initialize gives you this IDataObject
with no effort.

IContextMenu only gets called if you are dragging something into or out of
your namespace.

You can still get the above with IShellView::GetItemObject. You first
have to locate the window with the active view. You obtain the IShellView
through the IShellBrowser interface.









Drag/Drop from Filesystem

by Jim Barry » Fri, 03 Jun 2005 00:23:07 GMT




How about if you look at the CFSTR_SHELLIDLIST data? The first item in the CIDA represents the containing folder.

--
Jim Barry, MVP for Windows SDK


Drag/Drop from Filesystem

by Jim Barry » Fri, 03 Jun 2005 02:09:27 GMT




In that case I believe the containing folder is the desktop and the ID-lists are relative to that. (Which of course means that the ID-lists are fully qualified.)

--
Jim Barry, MVP for Windows SDK