帮我解释一下 下面的代码的含义?每一行都说明一下 30
其中CMyOleDataSource是COleDataSource的派生类CMyOleDataSource*pods=newCMyOleDataSource();pOle...
其中CMyOleDataSource 是COleDataSource 的派生类
CMyOleDataSource* pods = new CMyOleDataSource();
pOleDataSource = pods;
UINT uFileCount = m_fileList.GetSelectedCount();
UINT uBuffSize = sizeof(FILEGROUPDESCRIPTOR) +
(uFileCount-1) * sizeof(FILEDESCRIPTOR);
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;
POSITION pos = m_fileList.GetFirstSelectedItemPosition();
TRACE("pos%d",pos);
int index = 0;
pods->m_Files.RemoveAll();
while( NULL != pos )
{
int nSelItem = m_fileList.GetNextSelectedItem( pos );
TRACE("nSelItem%d",nSelItem);
ZeroMemory(&pFileDescriptorArray[index],
sizeof(FILEDESCRIPTOR));
lstrcpy ( pFileDescriptorArray[index].cFileName,
m_fileList.GetItemText( nSelItem, 0 ) );
pods->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 };
pods->CacheGlobalData ( RegisterClipboardFormat(
CFSTR_FILEDESCRIPTOR), hFileDescriptor, &etcDescriptor );
FORMATETC etcContents = {
RegisterClipboardFormat(CFSTR_FILECONTENTS),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
pods->DelayRenderFileData(RegisterClipboardFormat(
CFSTR_FILECONTENTS), &etcContents);
pods->SetClipboard();
/////////////////////////////////////////////////////////////
下面是CMyOleDataSource类的定义
// MyOleDataSource.h: interface for the CMyOleDataSource class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_)
#define AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_
#include<afxole.h>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMyOleDataSource: public COleDataSource
{
public:
CStringArray m_Files;
CMyOleDataSource();
virtual ~CMyOleDataSource();
virtual BOOL OnRenderFileData(
LPFORMATETC lpFormatEtc,CFile* pFile);
};
#endif // !defined(AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_)
#include "MyOleDataSource.h"
// Construction/Destruction
BOOL CMyOleDataSource::OnRenderFileData(LPFORMATETC lpFormatEtc,CFile* pFile)
{
if(lpFormatEtc->cfFormat ==
RegisterClipboardFormat(CFSTR_FILECONTENTS))
{
HGLOBAL hGlob = NULL;
const int buffSize = 512;
hGlob = GlobalAlloc(GMEM_FIXED, buffSize);
if(hGlob)
{
LPBYTE pBytes = (LPBYTE)GlobalLock(hGlob);
if(pBytes)
{
memset(pBytes, (int) m_Files.GetAt(
lpFormatEtc->lindex)[0], buffSize);
pFile->Write(pBytes,buffSize);
}
GlobalUnlock(hGlob);
}
GlobalFree(hGlob);
return TRUE;
}
// COleDataSource::DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_MOVE);
return COleDataSource::OnRenderFileData(lpFormatEtc,pFile);
}
这是类CMyOleDataSource的实现文件
说的好的,我可以加分200,知道里没有什么高手呀!!! 展开
CMyOleDataSource* pods = new CMyOleDataSource();
pOleDataSource = pods;
UINT uFileCount = m_fileList.GetSelectedCount();
UINT uBuffSize = sizeof(FILEGROUPDESCRIPTOR) +
(uFileCount-1) * sizeof(FILEDESCRIPTOR);
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;
POSITION pos = m_fileList.GetFirstSelectedItemPosition();
TRACE("pos%d",pos);
int index = 0;
pods->m_Files.RemoveAll();
while( NULL != pos )
{
int nSelItem = m_fileList.GetNextSelectedItem( pos );
TRACE("nSelItem%d",nSelItem);
ZeroMemory(&pFileDescriptorArray[index],
sizeof(FILEDESCRIPTOR));
lstrcpy ( pFileDescriptorArray[index].cFileName,
m_fileList.GetItemText( nSelItem, 0 ) );
pods->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 };
pods->CacheGlobalData ( RegisterClipboardFormat(
CFSTR_FILEDESCRIPTOR), hFileDescriptor, &etcDescriptor );
FORMATETC etcContents = {
RegisterClipboardFormat(CFSTR_FILECONTENTS),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
pods->DelayRenderFileData(RegisterClipboardFormat(
CFSTR_FILECONTENTS), &etcContents);
pods->SetClipboard();
/////////////////////////////////////////////////////////////
下面是CMyOleDataSource类的定义
// MyOleDataSource.h: interface for the CMyOleDataSource class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_)
#define AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_
#include<afxole.h>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMyOleDataSource: public COleDataSource
{
public:
CStringArray m_Files;
CMyOleDataSource();
virtual ~CMyOleDataSource();
virtual BOOL OnRenderFileData(
LPFORMATETC lpFormatEtc,CFile* pFile);
};
#endif // !defined(AFX_MYOLEDATASOURCE_H__B23F9B80_7A52_4CDD_8B01_D31D506D0B74__INCLUDED_)
#include "MyOleDataSource.h"
// Construction/Destruction
BOOL CMyOleDataSource::OnRenderFileData(LPFORMATETC lpFormatEtc,CFile* pFile)
{
if(lpFormatEtc->cfFormat ==
RegisterClipboardFormat(CFSTR_FILECONTENTS))
{
HGLOBAL hGlob = NULL;
const int buffSize = 512;
hGlob = GlobalAlloc(GMEM_FIXED, buffSize);
if(hGlob)
{
LPBYTE pBytes = (LPBYTE)GlobalLock(hGlob);
if(pBytes)
{
memset(pBytes, (int) m_Files.GetAt(
lpFormatEtc->lindex)[0], buffSize);
pFile->Write(pBytes,buffSize);
}
GlobalUnlock(hGlob);
}
GlobalFree(hGlob);
return TRUE;
}
// COleDataSource::DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_MOVE);
return COleDataSource::OnRenderFileData(lpFormatEtc,pFile);
}
这是类CMyOleDataSource的实现文件
说的好的,我可以加分200,知道里没有什么高手呀!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询