Question: CanDropOLEDataObject Example ?

I'm trying to get the pathname of a file that is being dragged and dropped onto my layer. An example would be very helpful and appreciated.

Environment

FalconView Version: FalconView 4.0.1
Interface: ILayerEditor
Language: Visual C++

(EDIT ICON)

-- Main.ScottOHanian - 05 Oct 2007

Answer

// query for the IDataObject interface
IDataObjectPtr spDataObject = pDataObject;

FORMATETC formatEtc;
formatEtc.cfFormat = CF_HDROP;
formatEtc.ptd = NULL;
formatEtc.dwAspect = FVASPECT_CONTENT;
formatEtc.lindex = -1;
formatEtc.tymed = (DWORD) -1;

if (spDataObject->QueryGetData(&formatEtc) == S_OK)
{
   STGMEDIUM std_medium;
   HGLOBAL hglobal = 0;

   // get the file name and extension from the IDataObject
   spDataObject->GetData(&formatEtc, &std_medium);
   if (stg_medium.tymed == TYMED_HGLOBAL)
      hglobal = std_medium.hGlobal;

   // how many files were dropped
   UINT nFileCount = DragQueryFile( (HDROP)hglobal, 0xffffffff, NULL, 0);

   // get the name of each file
   for(UINT i=0; i<nFileCount; ++i)
   {
      char filename[MAX_PATH];
      DragQueryFile( (HDROP)hglobal, i, buffer, MAX_PATH);

      // do something with filename here
   }
}