PrinterSettings - Changing, Storing and Loading Printer Settings | CodeGuru

PrinterSettings – Changing, Storing and Loading Printer Settings

Description Several years ago I had to implement the ability to change the printer and it’s settings from within a programm. The output had to be distributed to 3 or more printers. The settings had to be stored to disk to be able to be loaded. It was desired to conform to the MFC Framework. […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 1, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Description

Several years ago I had to implement the ability to change
the printer and it’s settings from within a programm.
The output had to be distributed to 3 or more printers.
The settings had to be stored to disk to be able to be loaded.
It was desired to conform to the MFC Framework.

How to use

Declare the class CPrinterSettings in a CDocument derived class
or wherever you find it useful.

#include “PrinterSettings.h”
class CPrnsetupDlg : public CDialog
{
public:
	CPrinterSettings m_prn_setting1;
	CPrinterSettings m_prn_setting2;

To get a copy of the original MFC printer settings
call CopyDefaultMfcPrinter().

	// Get MFC’s default printer
	m_prn_setting1.CopyDefaultMfcPrinter();
	m_prn_setting2.CopyDefaultMfcPrinter();

To let the user change the settings
e.g. paper orientation or printer resolution
call PrinterSetup( CWnd* pWnd ).

	m_prn_setting1.PrinterSetup(this);

To cause MFC to use your settings call
SetThisPrinter().

	// make m_prn_setting1 the MFC standard printer
	m_prn_setting1.SetThisPrinter();
	// later you may call RestorePrinter() to
	// restore earlier settings.

To load or save your settings call
Save(LPCTSTR filename ) or Load(LPCTSTR filename ).

	// Save our settings to file
	m_prn_setting1.Save( “testfilename”);
	…
	…
	// load settings, store them in m_prn_settings1
	m_prn_setting1.Load( “testfilename” ));
Advertisement

Downloads

Download demo project – 17 Kb

The name of the project is “prnsetup.dsw” (build with VC 6 )

Download source – 5 Kb

The source files are named: PrinterSettings.h and PrinterSettings.cpp

History

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.