📄 axserverview.cpp
字号:
// AxServerView.cpp : implementation of the CAxServerView class
//
#include "stdafx.h"
#include "AxServer.h"
#include "AxServerDoc.h"
#include "AxServerView.h"
#include "srvritem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAxServerView
IMPLEMENT_DYNCREATE(CAxServerView, CView)
BEGIN_MESSAGE_MAP(CAxServerView, CView)
//{{AFX_MSG_MAP(CAxServerView)
ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAxServerView construction/destruction
CAxServerView::CAxServerView()
{
// TODO: add construction code here
m_prevDropEffect = DROPEFFECT_NONE;
}
CAxServerView::~CAxServerView()
{
}
BOOL CAxServerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CAxServerView drawing
void CAxServerView::OnDraw(CDC* pDC)
{
CAxServerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDoc->Draw(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CAxServerView printing
BOOL CAxServerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CAxServerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CAxServerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// OLE Server support
// The following command handler provides the standard keyboard
// user interface to cancel an in-place editing session. Here,
// the server (not the container) causes the deactivation.
void CAxServerView::OnCancelEditSrvr()
{
GetDocument()->OnDeactivateUI(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CAxServerView diagnostics
#ifdef _DEBUG
void CAxServerView::AssertValid() const
{
CView::AssertValid();
}
void CAxServerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CAxServerDoc* CAxServerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAxServerDoc)));
return (CAxServerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAxServerView message handlers
void CAxServerView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
pDC->SetMapMode(MM_ANISOTROPIC);
// 其他设置代码
CView::OnPrepareDC(pDC, pInfo);
}
void CAxServerView::OnEditCopy()
{
// TODO: Add your command handler code here
CAxServerDoc* pDoc=GetDocument();
CAxServerSrvrItem *pItem=pDoc->GetEmbeddedItem();
TRY
{
//pDataSource = new COleDataSource;
COleDataSource* pDataSource = pItem->OnGetClipboardData(TRUE, NULL, NULL);
// put on local format instead of or in addation to
if(pDoc->m_cfPrivate != NULL)
{
STGMEDIUM stgMedium;
pItem->GetEmbedSourceData(&stgMedium);
pDataSource->CacheData(pDoc->m_cfPrivate, &stgMedium);
}
pDataSource->SetClipboard();
}
CATCH_ALL(e)
{
THROW_LAST();
}
END_CATCH_ALL
}
void CAxServerView::OnEditCut()
{
// TODO: Add your command handler code here
// 调用复制函数
OnEditCopy();
// 删除数据
// 更新所有视图
CAxServerDoc* pDoc=GetDocument();
pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(NULL);
}
void CAxServerView::OnEditPaste()
{
// TODO: Add your command handler code here
CAxServerDoc* pDoc=GetDocument();
// 从剪贴板中获得数据
COleDataObject clipboardData;
clipboardData.AttachClipboard();
// 判断剪贴板中数据的类型
if (clipboardData.IsDataAvailable(pDoc->m_cfPrivate))
{
// 剪贴板中数据是自身的数据类型,则进行内部复制操作
// 更新所有视图
pDoc->SetModifiedFlag();
pDoc->UpdateAllViews(NULL);
}
else
return;
}
int CAxServerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// 拖放对象的注册
m_dropTarget.Register(this);
return 0;
}
void CAxServerView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// 确定对象的大小和位置
CClientDC dc(this);
CRect rect(0,0,120,120);
// 得到用于生成剪贴板数据的服务器对象
CAxServerDoc* pDoc=GetDocument();
CAxServerSrvrItem *pItem=pDoc->GetEmbeddedItem();
ASSERT_VALID(pItem);
// 计算偏移点并将对象的大小和位置转换到屏幕坐标转换
dc.LPtoDP(&rect);
CPoint ptOffset = point - rect.TopLeft();
ClientToScreen(&rect);
// 开始拖放对象
if (pItem->DoDragDrop(rect, ptOffset, TRUE,
DROPEFFECT_COPY | DROPEFFECT_MOVE) == DROPEFFECT_MOVE)
{
// 如果以移动对象则在此处添加删除代码
// 更新所有视图
pDoc->UpdateAllViews(NULL);
}
CView::OnLButtonDown(nFlags, point);
}
DROPEFFECT CAxServerView::OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
// TODO: Add your specialized code here and/or call the base class
ASSERT(m_prevDropEffect==DROPEFFECT_NONE);
return CView::OnDragEnter(pDataObject, dwKeyState, point);
}
DROPEFFECT CAxServerView::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
// TODO: Add your specialized code here and/or call the base class
DROPEFFECT dropEffect = DROPEFFECT_NONE;
// 复制链接
if ((dwKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT))
dropEffect = DROPEFFECT_COPY;
// 复制
else if ((dwKeyState & MK_CONTROL) == MK_CONTROL)
dropEffect = DROPEFFECT_COPY;
// 剪切(移动)
else if ((dwKeyState & MK_ALT) == MK_ALT)
dropEffect = DROPEFFECT_MOVE;
else
dropEffect = DROPEFFECT_MOVE;
// 纪录拖动效果
m_prevDropEffect = dropEffect;
return dropEffect;
// return CView::OnDragOver(pDataObject, dwKeyState, point);
}
void CAxServerView::OnDragLeave()
{
// TODO: Add your specialized code here and/or call the base class
m_prevDropEffect = DROPEFFECT_NONE;
// CView::OnDragLeave();
}
BOOL CAxServerView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)
{
// TODO: Add your specialized code here and/or call the base class
m_prevDropEffect = DROPEFFECT_NONE;
return CView::OnDrop(pDataObject, dropEffect, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -