- •Id_indicator_caps,
- •Id_indicator_num,
- •Id_indicator_scrl,
- •Virtual void Serialize(cArchive& ar);
- •Implement_dyncreate(ccontDoc, cOleDocument)
- •Void ccontView::OnDraw(cdc* pDc) // Обработчик сообщения
- •Void ccontView::OnBeginPrintiBg(cdc* /*pDc*/, cPrintlnfo* /*рШо*/) {
- •Void ccontView::OnDestroy() {
- •Void ccontView::OnSetFocns(cWnd* pOldWnd)
- •Void ccontView::AssertValid() const
Void ccontView::OnSetFocns(cWnd* pOldWnd)
{
COleClientltem* pActiveltem = GetDocuraent()->GetInPIaceActiveItem(this);
if (pActiveltem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState) {
// need to set focus to this item if it is in the same view CWnd* pWnd = pActiveItem->GetInPlaceWindow(); if (pWnd != NULL) {
pWnd->SetFocus(); // don't call the base class return; } }
CView::OnSetFocus(pOWWnd); }
void CCONTView::OnSize(UlNT nType, int ex, int cy) {
CView::0nSi2e(nType, ex, cy);
COleClientltem* pActiveltem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveltem != NULL)
pActiveItem->SetItemRects(); }
Illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll II CCONTView diagnostics
#ifdef_DEBUG
Void ccontView::AssertValid() const
{ CView::AssertValid();}
void CCONTView: :Dump(CDumpContext& dc) const
{ CView::Dump(dc);}
CCONTDoc* CCONTView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCONTDoc)));
return (CCONTDoc*)m_pDocument; } #endif//_DEBUG
Illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll II CCONTView message handlers
Листинг файла Cntrltem.h
class CCONTCntrltem : public COleClientltem {
DECLARE_SERIAL(CCONTCntrItem)
// Constructors public:
CCONTCntrItem(CCONTDoc* pContainer = NULL); // Note: pContainer is allowed to be NULL to enable IMPLEMENT_SERIALIZE.
// IMPLEMENT_SERIALIZE requires the class have a constructor with // zero arguments. Normally, OLE items are constructed with a // non-NULL document pointer. // Attributes public:
CCONTDoc* GetDocumentO
{ return (CCONTDoc*)COleClientItem::GetDocument();}
CCONTView* GetActiveView()
{return (CCONTView*)COleClientItem::GetActiveView();}
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCONTCntrItem)
public:
virtual void OnChange(OLE_NOTIFICATION wNotification, DWORD dwParam);
virtual void OnActivate();
protected:
virtual void OnGetItemPosition(CRect& rPosition);
virtual void OnDeactivateUI(BOOL bUndoable);
virtual BOOL OnChangeItemPosition(const CRect& rectPos);
//}}AFX_VIRTUAL // Implementation public:
~CCONTCntrItem(); #ifdef_DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const; #endif
virtual void Serialize(CArchive& ar);
};
Illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
//{{AFX_INSERT_LOCATION}}
// Developer Studio will insert additional declarations immediately before the previous line.
Листинг файла Cntrltem.cpp
«include "stdafx.h" «include "CONT.h" «include "CONTDoc.h" «include "CONTView.h" «include "Cntrltem.h"
#ifdef_DEBUG
«define new DEBUG_NEW
#undefTHIS_FILE
static char THIS_FILE[] = _FILE_;
#endif.
llllllllllllllllllllllllllllllllllllllllllhlllllllllllllllllllllllllllllllll II CCONTCntrltem implementation IMPLEMENT_SERIAL(CCONTCntrItem, COleClientltem, 0)
CCONTCntrItem::CCONTCntrItem(CCONTDoc*pContainer)
: COleClientltem(pContainer) {
// TODO: add one-time construction code here
}
CCONTCntrItem::~CCONTCntrItem() {
// TODO: add cleanup code here } void CCONTCntrItem::OnOiange(OLE_NOTIFICATION nCode, DWORD dwParam)
ASSERT_VALID(this);
COleClientItem::OnChange(nCode, dwParam);
// When an item is being edited (either in-place or fully open)
// it sends OnChange notifications for changes in the state of the
// item or visual appearance of its content.
// TODO: invalidate the item by calling UpdateAllViews
// (with hints appropriate to your application)
GetDocument()->UpdateA!lViews(NULL);
// for now just update ALL views/no hints } BOOL CCONTCntrltem::OnChangeItemPosition(const CRect& rectPos)
ASSERT_VALID(this);
// During in-place activation CCONTCntrItem::OnChangeItemPosition
// is called by the server to change the position of the in-place
// window. Usually, this is a result of the data in the server
// document changing such that the extent has changed or as a result
// of in-place resizing.
//
// The default here is to call the base class, which will call
// COleClientItem::SetItemRects to move the item
// to the new position.
if (!COleCUentItem::OnChangeItemPosition(rectPos)) return FALSE;
// TODO: update any cache you may have of the item's rectangle/extent
return TRUE; } void CCONTCntrItem::OnGetItemPosition(CRect& rPosition)
{
ASSERT_VALID(this);
// During in-place activation, CCONTCntrltem: :OnGetItemPosition
// will be called to determine the location of this item. The default
// implementation created from AppWizard simply returns a hard-coded
// rectangle. Usually, this rectangle would reflect the current
// position of the item relative to the view used for activation.
// You can obtain the view by calling CCONTCntrltem ::GetActiveView.
// TODO: return correct rectangle (in pixels) in rPosition
rPosition.SetRect(10, 10, 210, 210);
}
void CCONTCntrItem::OnActivate()
{
// Allow only one inplace activate item per frame CCONTView* pView = GetActiveViewO; ASSERT_VALID(pView);
COleClientltem* pltem = GetDocument()->GetInPlaceActiveItem(pView); if (pltem != NULL && pltem != this) pItem->Close(); COleClientItem::OnActivate();
}
void CCONTCntrItem::OnDeactivateUI(BOOL bUndoable)
{
COleClientItem::OnDeactivateUI(bUndoable);
// Hide the object if it is not an outside-in object DWORD dwMisc = 0;
m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc); if (dwMisc & OLEMISCJNSIDEOUT) DoVerb(OLEIVERB_HIDE, NULL);
)
void CCONTCntrItem::Serialize(CArchive& ar)
{ ASSERT_VALID(this);
// Call base class first to read in COleClientltem data.
// Since this sets up the m_pDocument pointer returned from
// CCONTCntrItem::GetDocument, it is a good idea to call
// the base class Serialize first.
COleClientItem::Serialize(ar);
// now store/retrieve data specific to CCONTCntrltem
if (ar.IsStoringO)
{ // TODO: add storing code here
}
else
{ // TODO: add loading code here } }
II CCONTCntrltem diagnostics
#ifdef_DEBUG
void CCONTCntrItem::AssertValid() const
{ COleClientItem::AssertValid();}
void CCONTCntrItem::Dump(CDumpContext& dc) const
{ C01eClientItem::Dump(dc);}
#endif
IIIIIIIIIIIUIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIH Листинг файла stdafx.cpp
#include "stdafx.h"
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by CONT.RC
//
#defme IDR_MAINFRAME 128
#define IDR_CONTTYPE 129
#define IDR_CNTR_INPLACE 6
#define IDD_ABOUTBOX 100
#defme IDP_OLE_INIT_FAILED 100
#define IDP_FAILED_TO_CREATE 102
#defme ID_CANCEL_EDIT_CNTR 32768
// Next default values for new objects
//
#ifdef APSTUDIOJNVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_JD_CONTROLS 1
#defme _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#defme _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
После того как AppWizard автоматически создал все файлы шаблона приложения, проект можно откомпилировать и выполнить.
На рис. 6 показан результат выполнения созданного шаблона SDI-при-ложения OLE-контейнера.
Рис. 6. Общий вид главного окна SDI-приложения
Встраивание любого OLE-объекта, поддерживаемого операционной системой, реализовано командой меню Edit | Insert New Object.
Если встраиваемый OLE-объект может редактироваться на месте OLE-сервером, то меню главного окна приложения заменяется на меню OLE-сервера.
На рис. 7 приведен пример использования созданного OLE-контейнера для объекта "Диаграмма Microsoft Excel".
Рис. 7. Окно приложения с внедренным объектом "Диаграмма Microsoft Excel"