asked on
ASKER
ASKER
public ref class DnDListView : public ListView
{
public:
DnDListView() { m_pDataSrc = new CMyOleDataSource(); }
~DnDListView() { delete m_pDataSrc; }
/** Override the OnItemDrag method to handle the native
code used for virtual file DnD. */
virtual void OnItemDrag(ItemDragEventArgs ^e) override
{
UINT uFileCount = this->SelectedItems->Count;
UINT uBuffSize = sizeof(FILEGROUPDESCRIPTOR) +
(uFileCount-1) * sizeof(FILEDESCRIPTOR);
HGLOBAL hFileDescriptor = GlobalAlloc (
GHND | GMEM_SHARE, uBuffSize );
if(hFileDescriptor)
{
FILEGROUPDESCRIPTOR* pGroupDescriptor =
(FILEGROUPDESCRIPTOR*) GlobalLock ( hFileDescriptor );
if(pGroupDescriptor)
{
FILEDESCRIPTOR* pFileDescriptorArray =
(FILEDESCRIPTOR*)((LPBYTE)pGroupDescriptor + sizeof(UINT));
pGroupDescriptor->cItems = uFileCount;
int index = 0;
m_pDataSrc->m_Files->RemoveAll();
for (int i = 0; i < uFileCount; ++i)
{
ZeroMemory(&pFileDescriptorArray[index],
sizeof(FILEDESCRIPTOR));
pin_ptr<const wchar_t> wch = PtrToStringChars(this->SelectedItems[i]->Text);
CString fileName(wch);
lstrcpy ( pFileDescriptorArray[index].cFileName, fileName );
m_pDataSrc->m_Files->Add(pFileDescriptorArray[index].cFileName);
pFileDescriptorArray[index].dwFlags = FD_FILESIZE|FD_ATTRIBUTES;
pFileDescriptorArray[index].nFileSizeLow = 512;
pFileDescriptorArray[index].nFileSizeHigh = 0;
pFileDescriptorArray[index].dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
index++;
}
}
else
{
GlobalFree ( hFileDescriptor );
}
}
GlobalUnlock ( hFileDescriptor );
FORMATETC etcDescriptor = {
RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
m_pDataSrc->CacheGlobalData ( RegisterClipboardFormat(
CFSTR_FILEDESCRIPTOR), hFileDescriptor, &etcDescriptor );
FORMATETC etcContents = {
RegisterClipboardFormat(CFSTR_FILECONTENTS),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
m_pDataSrc->DelayRenderFileData(
RegisterClipboardFormat(CFSTR_FILECONTENTS),
&etcContents);
DROPEFFECT dwEffect = m_pDataSrc->DoDragDrop (
DROPEFFECT_COPY | DROPEFFECT_MOVE );
if(dwEffect == DROPEFFECT_NONE )
{
GlobalFree( hFileDescriptor );
}
}
protected:
CMyOleDataSource * m_pDataSrc;
};
ASKER
ASKER
ASKER
ASKER
ASKER
C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).
TRUSTED BY
Sometimes the debugger points to the wrong line, so check that. I sugggest that you breakpoint on that line and single-step into the MFC source code.