Click here to Skip to main content
15,891,810 members
Articles / Programming Languages / C++

CPrintPreviewListBox

Rate me:
Please Sign up or sign in to vote.
4.83/5 (5 votes)
28 Dec 2000 85.1K   3.1K   37  
A listbox derived class with printing and print preview in SDI and MDI applications
In this article, you will find a listbox derived class that allows printing and print preview in SDI and MDI applications.
#if !defined(AFX_PRINTPREVIEWLISTBOX_H__2387B38F_AA48_4B5C_A515_C9E487058728__INCLUDED_)
#define AFX_PRINTPREVIEWLISTBOX_H__2387B38F_AA48_4B5C_A515_C9E487058728__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PrintPreviewListBox.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CPrintPreviewListBox window

#include <afxtempl.h>

/*****************************************************************************/
/*                                                                           */
/* .CLASSNAME: [CPrintPreviewListBox           ]                             */
/*                                                                           */
/* .BASECLASSNAMES:                                                          */
/*  CListBox, .....                                                          */
/*                                                                           */
/* .DESCRIPTION:                                                             */
/*  .......                                                                  */
/*                                                                           */
/* .REPORT                                                                   */
/*  dd.mm.yy  Goran      Extended CListBox class                             */
/*  ........  .........  ................................................... */
/*                                                                           */
/*****************************************************************************/
class CPrintPreviewListBox : public CListBox
{
	CFont m_printerFont;
	UINT m_cyPrinter;

	UINT m_nLinesPerPage;
	UINT m_nLinesTotal;

	UINT m_cxOffset;
	UINT m_cxWidth;

	CString m_strTitle;

	bool m_bPrintOnlySelectedItems;
	bool m_bIsMultiselection;

	CArray<int,int> aryListBoxSel;
	CStringArray m_strarFinalArray;

protected:
	virtual int SetLinesTotal();
	void LineBreaking( CString sSelectedItem );

	virtual void PrintPageHeader (CDC*, UINT);
	virtual void PrintPage (CDC*, UINT);

// Construction
public:
	CPrintPreviewListBox();
	DECLARE_DYNCREATE(CPrintPreviewListBox)

// Attributes
public:

// Operations
public:
	void Print();

	void SetPrintTitle( CString sNewTitle = "Default title" );
	CString GetPrintTitle();

	void SetOnlySelectedItems( bool bOnlySelectedItems );
	bool GetOnlySelectedItems();

	virtual void OnBeginPrinting (CDC*, CPrintInfo*);
	virtual void OnPrint (CDC*, CPrintInfo*);
	virtual void OnEndPrinting (CDC*, CPrintInfo*);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPrintPreviewListBox)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CPrintPreviewListBox();

	// Generated message map functions
protected:
	//{{AFX_MSG(CPrintPreviewListBox)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};
/*****************************************************************************/

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_PRINTPREVIEWLISTBOX_H__2387B38F_AA48_4B5C_A515_C9E487058728__INCLUDED_)

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.


Written By
Web Developer student
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions