Oj to źle jeśli u Ciebie jest inna nazwa tego formatu; czyżbym musiał porównywać te formaty według nazwy ?
Prawdę mówiąc RegisterClipboardFormat zwraca losowe wartości, więc raczej tak.
Yup, napisałem to tak:
IDropTargetNoRefs :: DragEnter(IDataObject *pDataObj,DWORD grfKeyState,POINTL *pt,DWORD *pdwEffect),HRESULT
{
STGMEDIUM medium;
if FindFormat(pDataObj, medium)
{
ReleaseStgMedium(medium);
return S_OK;
}
pdwEffect = DROPEFFECT_NONE;
return S_FALSE;
}
IDropTargetNoRefs :: Drop(IDataObject *pDataObj,DWORD grfKeyState,POINTL *pt,DWORD *pdwEffect),HRESULT
{
LRESULT not_processed = 1;
STGMEDIUM medium;
if FindFormat(pDataObj, medium)
{
not_processed = SendMessage(m_hwndParent, WM_DROPFILES, medium.hGlobal, 0);
if (not_processed) ReleaseStgMedium(medium);
}
return S_OK;
}
// custom named constant (ansi version)
//#define CF_UniformResourceLocator 0xC0B7
// custom method
IDropTargetNoRefs :: FindFormat(IDataObject *pDataObj, /*out*/STGMEDIUM outmedium),BOOL
{
IEnumFORMATETC *penumFormatetc;
FORMATETC etc;
STGMEDIUM medium;
if(!pDataObj->EnumFormatEtc(DATADIR_GET, &penumFormatetc))
{
ULONG celtFetched;
while (!penumFormatetc->Next(1, etc, &celtFetched))
{
if (etc.cfFormat == CF_HDROP)
{
// a local file
if (!pDataObj->GetData(etc, outmedium)) return true;
}
char cf_name[128];
GetClipboardFormatName(etc.cfFormat, cf_name, 128)
if (!strcmp(&cf_name, "UniformResourceLocator"))
{
// a anchor
if (!pDataObj->GetData(etc, medium))
{
string *data = GlobalLock(medium.hGlobal);
void *hdf = GlobalAlloc(GMEM_MOVEABLE, strlen(*data) + 1 + sizeof(DROPFILES));
if (hdf)
{
DROPFILES *df = GlobalLock(hdf);
if (df)
{
outmedium.tymed = TYMED_HGLOBAL;
outmedium.hGlobal = hdf;
outmedium.pUnkForRelease = null;
df->pFiles = sizeof(DROPFILES);
df->fWide = false;
strcpy(df+sizeof(DROPFILES), data);
GlobalUnlock(hdf);
GlobalUnlock(medium.hGlobal);
return true;
}
else GlobalFree(hdf);
}
GlobalUnlock(medium.hGlobal);
}
}
}
penumFormatetc->Release();
}
return false;
}