?? exampl~2.cpp
字號:
// ExampleView.cpp : CExampleView 類的實現(xiàn)
//
#include "stdafx.h"
#include "Example.h"
#include "ExampleDoc.h"
#include "CntrItem.h"
#include "ExampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CExampleView
IMPLEMENT_DYNCREATE(CExampleView, CView)
BEGIN_MESSAGE_MAP(CExampleView, CView)
ON_WM_DESTROY()
ON_WM_SETFOCUS()
ON_WM_SIZE()
ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
END_MESSAGE_MAP()
// CExampleView 構(gòu)造/銷毀
CExampleView::CExampleView()
{
m_pSelection = NULL;
// TODO: 在此處添加構(gòu)造代碼
}
CExampleView::~CExampleView()
{
}
BOOL CExampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此處通過修改 CREATESTRUCT cs 來修改窗口類或
// 樣式
return CView::PreCreateWindow(cs);
}
// CExampleView 繪制
void CExampleView::OnDraw(CDC* pDC)
{
CExampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 遍歷OLE項
POSITION pos=pDoc->GetStartPosition();
while(pos!=NULL)
{
// 顯示OLE項本身
CExampleCntrItem* pCurItem;
pCurItem=(CExampleCntrItem*) pDoc->GetNextClientItem(pos);
pCurItem->Draw(pDC,pCurItem->m_rect);
// 顯示跟蹤矩形
CRectTracker tracker;
SetupTracker(pCurItem,&tracker);
tracker.Draw(pDC);
}
}
void CExampleView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: 寫入最終選擇模式代碼之后移除此代碼
m_pSelection = NULL; // 初始化選定內(nèi)容
}
void CExampleView::OnDestroy()
{
// 停用處于銷毀中的項;這在
// 使用拆分器視圖時非常重要
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
CView::OnDestroy();
}
// OLE 客戶支持和命令
BOOL CExampleView::IsSelected(const CObject* pDocItem) const
{
// TODO: 實現(xiàn)對所選 OLE 客戶項進行測試的函數(shù)
return pDocItem == m_pSelection;
}
void CExampleView::OnInsertObject()
{
// 調(diào)用標準的“插入對象”對話框以獲得有關
// 新 CExampleCntrItem 對象的信息
COleInsertDialog dlg;
if (dlg.DoModal() != IDOK)
return;
BeginWaitCursor();
CExampleCntrItem* pItem = NULL;
TRY
{
// 創(chuàng)建與此文檔相連接的新項
CExampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CExampleCntrItem(pDoc);
ASSERT_VALID(pItem);
// 通過對話框數(shù)據(jù)初始化該項
if (!dlg.CreateItem(pItem))
AfxThrowMemoryException(); // 任何異常都將導致該結(jié)果
ASSERT_VALID(pItem);
if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
pItem->DoVerb(OLEIVERB_SHOW, this);
ASSERT_VALID(pItem);
// 作為任意用戶界面設計,這會將選定內(nèi)容
// 設置為插入的最后一項
// TODO: 重新實現(xiàn)選定內(nèi)容,使其適合于您的應用程序
m_pSelection = pItem; // 將選定內(nèi)容設置為插入的最后一項
pDoc->UpdateAllViews(NULL);
}
CATCH(CException, e)
{
if (pItem != NULL)
{
ASSERT_VALID(pItem);
pItem->Delete();
}
AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH
EndWaitCursor();
}
void CExampleView::OnCancelEditCntr()
{
// 關閉此視圖中的任何就地活動項。
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
{
pActiveItem->Close();
}
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
void CExampleView::OnSetFocus(CWnd* pOldWnd)
{
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState)
{
// 如果該項處于同一視圖中,則需要將焦點設置到該項
CWnd* pWnd = pActiveItem->GetInPlaceWindow();
if (pWnd != NULL)
{
pWnd->SetFocus(); // 不要調(diào)用基類
return;
}
}
CView::OnSetFocus(pOldWnd);
}
void CExampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
pActiveItem->SetItemRects();
}
void CExampleView::OnFilePrint()
{
CPrintInfo printInfo;
ASSERT(printInfo.m_pPD != NULL);
if (S_OK == COleDocObjectItem::DoDefaultPrinting(this, &printInfo))
return;
CView::OnFilePrint();
}
#ifdef _DEBUG
CExampleDoc* CExampleView::GetDocument() const // 非調(diào)試版本是內(nèi)聯(lián)的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExampleDoc)));
return (CExampleDoc*)m_pDocument;
}
#endif //_DEBUG
void CExampleView::SetupTracker(CExampleCntrItem *pItem, CRectTracker *pTracker)
{
// 設置跟蹤矩形的大小
pTracker->m_rect=pItem->m_rect;
// 設置跟蹤矩形邊框的風格
if(pItem==m_pSelection)
pTracker->m_nStyle|=CRectTracker::resizeInside;
if(pItem->GetType()==OT_LINK)
pTracker->m_nStyle|=CRectTracker::dottedLine;
else
pTracker->m_nStyle|=CRectTracker::solidLine;
if(pItem->GetItemState()==COleClientItem::openState ||
pItem->GetItemState()==COleClientItem::activeUIState)
pTracker->m_nStyle|=CRectTracker::hatchInside;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -