Click here to Skip to main content
15,884,388 members
Articles / Desktop Programming / MFC

MFC - Multiple inheritance and serialization

Rate me:
Please Sign up or sign in to vote.
4.80/5 (34 votes)
29 Oct 2003CPOL14 min read 163.4K   4.2K   73  
Describing a solution to allow namespaces, multiple inheritance, and serialization in an MFC program
#pragma once
#include "appdoc.h"

namespace GE_{ namespace App{

	class CAppView :
		public CScrollView,
		public Data::IViewAppQuery
	{
		DECLARE_DYNCREATE(CAppView);
	private:
		Data::QBase0 _pB0Hovered;	//the object the mouse is pointing
		Data::QBase0 _pB0Selected;	//the object selected (will receive commands)
		CRect _rcBounds;
		enum e_mode {
			md_normal,		//normal mode (mouse hovers the objects)
			md_drwdrag,		//mouse drag the selected object
			md_getcoord		//mouse moves in modal loop until the LBUTTON is pressed
		};
		e_mode _mode;			//current mode
		CPoint _pointClicked;	//the licked point
		struct XDrag	//dragging data structure
		{
			CPen pen;			//pen to draw the ghost
			CPoint pointBegin;	//where the drag began
			CRect rectDrag;		//the ghost rectangle
			Mfc::CAutoDC dc;	//DC to draw
			XDrag(CView* pView);
		};
		Safe::PtrStrong<XDrag> _pXDrag;	//normally null but _mode == md_drwdrag
		struct XGetCoord	//get coord data structure
		{
			CPoint pointGotten;
		};
		Safe::PtrStrong<XGetCoord> _pXGetCoord;	//non null when _mode == md_getcoord

		enum e_timers {
			tmr_null,		//no timers
			tmr_hover,		//reset everytime mouse move over an object. expires when the mose stop move
			tmr_longclick	//expires when LBUTTON remain pressed a long
		};
		void _SetHovered(Data::CBase0* pB0, CDC* pDC);		//changes the hovered object
		void _SetSelection(Data::CBase0* pB0, CDC* pDC);	//changes the selected object
		void _OnMouseMoveNormal(CPoint point);		//OnMouseMove in normal mode
		void _OnMouseMoveDrag(CPoint point);		//OnMouseMove in drag mode
		//Data::IViewAppQuery
		virtual CPoint DoClickCoord();		//loops in md_getcoord until a click, and returns the coord.
		virtual void InitCoord(Data::IAppViewable* pAV, CPoint point);	//re-initilize the layout for an object
	public:
		CAppView(void);
		~CAppView(void);
		CAppDoc* GetDocument() { return dynamic_cast<CAppDoc*>(CView::GetDocument()); }
	protected:
		virtual void OnDraw(CDC* pDC);
	public:
		DECLARE_MESSAGE_MAP()
		afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
		afx_msg void OnMouseMove(UINT nFlags, CPoint point);
		afx_msg void OnDestroy();
		afx_msg void OnTimer(UINT nIDEvent);
		afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
		afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
		//afx_msg void OnAddAssembled();
		//afx_msg void OnUpdateAddAssembled(CCmdUI *pCmdUI);
		//afx_msg void OnAddInterm1();
		//afx_msg void OnUpdateAddInterm1(CCmdUI *pCmdUI);
		//afx_msg void OnAddInterm2();
		//afx_msg void OnUpdateAddInterm2(CCmdUI *pCmdUI);
		//afx_msg void OnRemoveItem();
		//afx_msg void OnUpdateRemoveItem(CCmdUI *pCmdUI);
		afx_msg void OnBreakCmd();  //pressed ESC key
		virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
	protected:
		virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
	public:
		virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
	};

}}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions