Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC

MFC Extension library : Enhanced print preview plug-in

Rate me:
Please Sign up or sign in to vote.
4.65/5 (9 votes)
24 May 2004CPOL8 min read 67.8K   1.8K   49  
MFC Extension library : Enhanced print preview plug-in
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "mappedbitmapbutton.h"
#include "afxpriv.h"
#include <..\src\afximpl.h>

// override MFC class
class CMultiPagePreviewView : public CPreviewView
{
	DECLARE_DYNCREATE(CMultiPagePreviewView)
protected:
				CMultiPagePreviewView();
	virtual		~CMultiPagePreviewView();
public:
	// override
private:
	// these variables are used in the page layout algorithm
	int					m_Across;				// number across the page, >= 1
	int					m_Down;			    	// number down the page, >= 1
	CPoint				m_PageOffset;			// amount to move the page from one position to the next
	// bitmapped buttons in toolbar
	CMappedBitmapButton m_print;
	CMappedBitmapButton m_printSetup;
	CMappedBitmapButton m_next;
	CMappedBitmapButton m_previous;
	CMappedBitmapButton m_zoomIn;
	CMappedBitmapButton m_zoomOut;
	CMappedBitmapButton m_pages;
    // plug in library support
    CPlugInMap**	    m_pMaps;
	int				    m_MapCount;
	bool			    m_bSuppressThisMessage;
	CPIState		    m_state;
	
	//{{AFX_VIRTUAL(CMultiPagePreviewView)
protected:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
	virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	//virtual void OnDraw(CDC* pDC);
	//}}AFX_VIRTUAL
	
protected:
	virtual void	PositionPage(UINT nPage);
	void			SetScaledSize(UINT nPage);
	void			DoZoom(UINT nPage, CPoint point);
	void			SetZoomState(UINT nNewState, UINT nPage, CPoint point);
	CSize			CalcPageDisplaySize();
	void			SetupScrollbar();
    int             GetPrintOrientation() const;
    bool            SetPrintOrientation(int mode) const;
	// note that is you change the maximum number of pages that can be displayed in preview mode
	// you have to increase the size of this array to make sure there is an entry available for every
	// possible page that can be shown at once.
	PAGE_INFO		m_pageInfoArray2[9]; // Embedded array for the default implementation - replaces MFC one of size 2!

#ifdef _DEBUG
	virtual void	AssertValid() const;
	virtual void	Dump(CDumpContext& dc) const;
#endif
	
protected:
	//{{AFX_MSG(CMultiPagePreviewView)
	afx_msg int		OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void	OnNumPageChange();
	afx_msg void	OnZoomIn();
	afx_msg void	OnZoomOut();
	afx_msg void	OnUpdateNumPageChange(CCmdUI* pCmdUI);
	afx_msg void	OnUpdateZoomIn(CCmdUI* pCmdUI);
	afx_msg void	OnUpdateZoomOut(CCmdUI* pCmdUI);
	afx_msg void	OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg BOOL	OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void	OnPreviewPages();
	//}}AFX_MSG
	afx_msg BOOL	OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT * pResult);
	afx_msg void	OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void	OnLandscape();
	afx_msg BOOL	OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    afx_msg void    OnPrintSetup();
	DECLARE_MESSAGE_MAP()
};

// the additional zoom level factors that we support when zoomed in
// the default MFC range is 0 (ZOOMED_OUT), 1 and 2
#define ZOOM_IN_150     3
#define ZOOM_IN_200     4
#define ZOOM_IN_400     5

//{{AFX_INSERT_LOCATION}}

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
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.

I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)

I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

Comments and Discussions