A
Arvind Ghai
Hi,
Could you please help !
I am facing a problem in implementation of drag drop
between managed and unmanaged code.
I prepare a data object in managed environment to support
drag drop with a custom format.
DataObject dataOb = new DataObject();
DataFormats.Format myCustomFormat = DataFormats.GetFormat
("CustomFormat");
String data = "Custom Text";
dataOb.SetData(myCustomFormat.Name, data);
If the drop operation is completed over an Unmanaged
application's window (which is registered for Ole drop) I
use the following code slice.
void DropData(HWND hwnd, IDataObject *pDataObject)
{
UINT cF = RegisterClipboardFormat("CustomFormat");
FORMATETC fmtetc = {cF, 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL};
STGMEDIUM stgmed;
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
if(pDataObject->GetData(&fmtetc, &stgmed) ==
S_OK)
{
PVOID data = GlobalLock(stgmed.hGlobal);
SetWindowText(hwnd, (char *)data);
GlobalUnlock(stgmed.hGlobal);
ReleaseStgMedium(&stgmed);
}
}
}
Here I get problem. The resulting window text is not the
desired text "Custom Text", instead it gives some junk.
Also if the data is of different type other than string, I
don't know how to get desired presentation of data in
unmanaged code.
If I do the same exercise with standard data format as
DataFormats.Text (managed) and corresponding CF_TEXT
(unmanaged) it works fine.
Regards
Arvind
Could you please help !
I am facing a problem in implementation of drag drop
between managed and unmanaged code.
I prepare a data object in managed environment to support
drag drop with a custom format.
DataObject dataOb = new DataObject();
DataFormats.Format myCustomFormat = DataFormats.GetFormat
("CustomFormat");
String data = "Custom Text";
dataOb.SetData(myCustomFormat.Name, data);
If the drop operation is completed over an Unmanaged
application's window (which is registered for Ole drop) I
use the following code slice.
void DropData(HWND hwnd, IDataObject *pDataObject)
{
UINT cF = RegisterClipboardFormat("CustomFormat");
FORMATETC fmtetc = {cF, 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL};
STGMEDIUM stgmed;
if(pDataObject->QueryGetData(&fmtetc) == S_OK)
{
if(pDataObject->GetData(&fmtetc, &stgmed) ==
S_OK)
{
PVOID data = GlobalLock(stgmed.hGlobal);
SetWindowText(hwnd, (char *)data);
GlobalUnlock(stgmed.hGlobal);
ReleaseStgMedium(&stgmed);
}
}
}
Here I get problem. The resulting window text is not the
desired text "Custom Text", instead it gives some junk.
Also if the data is of different type other than string, I
don't know how to get desired presentation of data in
unmanaged code.
If I do the same exercise with standard data format as
DataFormats.Text (managed) and corresponding CF_TEXT
(unmanaged) it works fine.
Regards
Arvind