📄 interfacedroptarget.cpp
字号:
// InterfaceDropTarget.cpp: Implementierung der Klasse CInterfaceDropTarget.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "stdafx.h"
#include "InterfaceDropTarget.h"
#include "DropDialog.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
CInterfaceDropTarget::CInterfaceDropTarget()
{
}
CInterfaceDropTarget::~CInterfaceDropTarget()
{
}
DROPEFFECT CInterfaceDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
{
// this time we have to check every time what' our format
// because in this sample the format may change dynamically
UINT DragDropFormat;
CString format = AfxGetApp()->GetProfileString("DragDrop", "Clipformat", "Common");
if (format == "Private")
DragDropFormat = ::RegisterClipboardFormat("InterfaceClipboardFormat");
else
DragDropFormat = CF_TEXT;
CFile *pFile = pDataObject->GetFileData(DragDropFormat);
if (pFile != NULL)
// perhaps some point checking here?
return DROPEFFECT_COPY; // data fits
else
return DROPEFFECT_NONE; // data won抰 fit
}
BOOL CInterfaceDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point )
{
// this time we have to check every time what' our format
// because in this sample the format may change dynamically
UINT DragDropFormat;
CString format = AfxGetApp()->GetProfileString("DragDrop", "Clipformat", "Common");
if (format == "Private")
DragDropFormat = ::RegisterClipboardFormat("InterfaceClipboardFormat");
else
DragDropFormat = CF_TEXT;
CFile *pFile = pDataObject->GetFileData(DragDropFormat);
if (pFile != NULL)
{
int number, colCou;
CString Data;
// perhaps some point checking first?
TRY
{
CArchive ar(pFile, CArchive::load);
TRY
{
if (DragDropFormat != CF_TEXT)
{
// "Serialize" your data object from the archive
// (yes, you may use YourObject.Serialize(ar) here!)
ar >> number;
ar >> colCou;
for (int i=0; i<number; i++)
for (int j=0; j<colCou; j++)
{
ar >> Data ;
if (pWnd->IsKindOf(RUNTIME_CLASS(CDropDialog)))
((CDropDialog*)pWnd)->InsertData(i, j, Data);
}
}
else
{
CString Data, t;
TRY
{
while(ar.ReadString(t))
Data += t + "\n";
}
CATCH_ALL(eInnerMost)
{
#ifdef _DEBUG
TCHAR szCause[255];
CString strFormatted;
eInnerMost->GetErrorMessage(szCause, 255);
strFormatted = _T("Exception: ");
strFormatted += szCause;
AfxMessageBox(strFormatted);
#endif //_DEBUG
ASSERT(FALSE);
}
END_CATCH_ALL;
if (pWnd->IsKindOf(RUNTIME_CLASS(CDropDialog)))
((CDropDialog*)pWnd)->ProcessData(Data);
}
ar.Close();
}
CATCH_ALL(eInner)
{
// exception while reading from or closing the archive
ASSERT(FALSE);
}
END_CATCH_ALL;
}
CATCH_ALL(eOuter)
{
// exception in the destructor of ar
ASSERT(FALSE);
}
END_CATCH_ALL;
return TRUE;
}
return COleDropTarget::OnDrop(pWnd, pDataObject, dropEffect, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -