Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Fri Jan 16, 2009 11:15 am Post subject: HOWTO: Access binary data from dataobject in C++ during drag-drop |
|
|
When a drag-drop operation occurs over FolderView, The OnOnOleDragOver and OnOnOleDragDrop events occur. To get binary/HGLOBAL data from the data object, use the following code :
Code: | // FolderView OnOnOleDragDrop event handler
void CFdrViewVCDlg::OnOnOleDragDropFolderviewctrl1(LPDISPATCH Data, long effect, long Button, long Shift, float x, float y, LPDISPATCH Node, BOOL FAR* DoDefaultShellDropAction)
{
CFOVDataObject dataObject;
dataObject.AttachDispatch(Data,FALSE);
UINT cfFormat = ::RegisterClipboardFormat("<<custom data format>>"); // our custom data format
if (dataObject.GetFormat(cfFormat)) // Is data in that format present
{
// Get the data
VARIANT varBytes = dataObject.GetBinary(cfFormat);
//Binary data is stored in the variant as an array of unsigned char
if(varBytes.vt == (VT_ARRAY|VT_UI1)) // (OLE SAFEARRAY)
{
void *pArrayData;
//Obtain safe pointer to the array
SafeArrayAccessData(varBytes.parray,&pArrayData);
// Use data
// ...
// ...
//Unlock the variant data
SafeArrayUnaccessData(varBytes.parray);
}
VariantClear(&varBytes);
}
} |
|
|