prnsetupDlg.cpp
上传用户:jubilation
上传日期:2007-01-03
资源大小:18k
文件大小:7k
- // prnsetupDlg.cpp : Implementierungsdatei
- //
- #include "stdafx.h"
- #include "prnsetup.h"
- #include "prnsetupDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPrnsetupDlg Dialogfeld
- CPrnsetupDlg::CPrnsetupDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPrnsetupDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPrnsetupDlg)
- m_prn_filename1 = _T("");
- m_prn_filename2 = _T("");
- m_prn1 = _T("");
- m_prn2 = _T("");
- //}}AFX_DATA_INIT
- // Beachten Sie, dass LoadIcon unter Win32 keinen nachfolgenden DestroyIcon-Aufruf ben鰐igt
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CPrnsetupDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPrnsetupDlg)
- DDX_Control(pDX, IDC_LIST1, m_list);
- DDX_Text(pDX, IDC_PRN_FILENAME1, m_prn_filename1);
- DDX_Text(pDX, IDC_PRN_FILENAME2, m_prn_filename2);
- DDX_Text(pDX, IDC_PRN1, m_prn1);
- DDX_Text(pDX, IDC_PRN2, m_prn2);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPrnsetupDlg, CDialog)
- //{{AFX_MSG_MAP(CPrnsetupDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_CHOOSE_PRN1, OnChoosePrn1)
- ON_BN_CLICKED(IDC_CHOOSE_PRN2, OnChoosePrn2)
- ON_BN_CLICKED(IDC_SAVE_PRN1, OnSavePrn1)
- ON_BN_CLICKED(IDC_SAVE_PRN2, OnSavePrn2)
- ON_BN_CLICKED(IDC_LOAD_PRN1, OnLoadPrn1)
- ON_BN_CLICKED(IDC_LOAD_PRN2, OnLoadPrn2)
- ON_BN_CLICKED(IDC_PRINT_SAMPLE_PRN1, OnPrintSamplePrn1)
- ON_BN_CLICKED(IDC_PRINT_SAMPLE_PRN2, OnPrintSamplePrn2)
- ON_BN_CLICKED(IDC_GLOBAL_PRINTER, OnGlobalPrinter)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPrnsetupDlg Nachrichten-Handler
- BOOL CPrnsetupDlg::OnInitDialog()
- {
- // Get MFC's default printer
- m_prn_setting1.CopyDefaultMfcPrinter();
- m_prn_setting2.CopyDefaultMfcPrinter();
- m_prn1 = m_prn_setting1.GetPrinterName();
- m_prn2 = m_prn_setting2.GetPrinterName();
-
- CDialog::OnInitDialog();
- ShowMessage("printer 1 " + m_prn_setting1.GetPrinterName());
- ShowMessage("printer 2 " + m_prn_setting1.GetPrinterName());
-
- // Symbol f黵 dieses Dialogfeld festlegen. Wird automatisch erledigt
- // wenn das Hauptfenster der Anwendung kein Dialogfeld ist
- SetIcon(m_hIcon, TRUE); // Gro遝s Symbol verwenden
- SetIcon(m_hIcon, FALSE); // Kleines Symbol verwenden
-
- // ZU ERLEDIGEN: Hier zus鋞zliche Initialisierung einf黦en
-
- return TRUE; // Geben Sie TRUE zur點k, au遝r ein Steuerelement soll den Fokus erhalten
- }
- // Wollen Sie Ihrem Dialogfeld eine Schaltfl鋍he "Minimieren" hinzuf黦en, ben鰐igen Sie
- // den nachstehenden Code, um das Symbol zu zeichnen. F黵 MFC-Anwendungen, die das
- // Dokument/Ansicht-Modell verwenden, wird dies automatisch f黵 Sie erledigt.
- void CPrnsetupDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // Ger鋞ekontext f黵 Zeichnen
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Symbol in Client-Rechteck zentrieren
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Symbol zeichnen
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- void CPrnsetupDlg::ShowMessage(CString msg)
- {
- m_list.AddString(msg);
- m_list.SetCurSel( m_list.GetCount() - 1);
- }
- HCURSOR CPrnsetupDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CPrnsetupDlg::OnChoosePrn1()
- {
- m_prn_setting1.PrinterSetup(this);
- m_prn1 = m_prn_setting1.GetPrinterName();
- UpdateData(FALSE);
- ShowMessage("printer 1 " + m_prn_setting1.GetPrinterName());
- }
- void CPrnsetupDlg::OnChoosePrn2()
- {
- m_prn_setting2.PrinterSetup(this);
- m_prn2 = m_prn_setting2.GetPrinterName();
- UpdateData(FALSE);
- ShowMessage("printer 2 " + m_prn_setting2.GetPrinterName());
- }
- void CPrnsetupDlg::OnSavePrn1()
- {
- UpdateData();
- if(m_prn_filename1.IsEmpty()) {
- ShowMessage("filename for printer 1 is empty");
- return;
- }
- NO_ERROR == m_prn_setting1.Save( m_prn_filename1)
- ? ShowMessage("Save Printer1 ok for " + m_prn_filename1)
- : ShowMessage("Save Printer1 error for " + m_prn_filename1);
- }
- void CPrnsetupDlg::OnSavePrn2()
- {
- UpdateData();
- if(m_prn_filename2.IsEmpty()) {
- ShowMessage("filename for printer 2 is empty");
- return;
- }
- NO_ERROR == m_prn_setting2.Save( m_prn_filename2)
- ? ShowMessage("Save Printer2 ok for " + m_prn_filename2)
- : ShowMessage("Save Printer2 error for " + m_prn_filename2);
- }
- void CPrnsetupDlg::OnLoadPrn1()
- {
- UpdateData();
- if(m_prn_filename1.IsEmpty()) {
- ShowMessage("filename for printer 1 is empty");
- return;
- }
- // load settings, store them in m_prn_settings1
- (NO_ERROR == m_prn_setting1.Load( m_prn_filename1))
- ? ShowMessage("Load Printer1 ok for " + m_prn_filename1)
- : ShowMessage("Load Printer1 error for " + m_prn_filename1);
- m_prn1 = m_prn_setting1.GetPrinterName();
- UpdateData(FALSE);
- ShowMessage("printer 1 " + m_prn_setting1.GetPrinterName());
- }
- void CPrnsetupDlg::OnLoadPrn2()
- {
- UpdateData();
- if(m_prn_filename2.IsEmpty()) {
- ShowMessage("filename for printer 2 is empty");
- return;
- }
- // load settings, store them in m_prn_settings2
- NO_ERROR == m_prn_setting2.Load( m_prn_filename2)
- ? ShowMessage("Load Printer2 ok for " + m_prn_filename2)
- : ShowMessage("Load Printer2 error for " + m_prn_filename2);
- m_prn2 = m_prn_setting2.GetPrinterName();
- UpdateData(FALSE);
- ShowMessage("printer 2 " + m_prn_setting2.GetPrinterName());
- }
- void CPrnsetupDlg::OnPrintSamplePrn1()
- {
- // make m_prn_setting1 the MFC standard printer
- m_prn_setting1.SetThisPrinter();
- // Get DC of actual standard printer
- CDC dc;
- AfxGetApp()->CreatePrinterDC(dc);
- DOCINFO di;
- ZeroMemory(&di,sizeof(DOCINFO));
- di.cbSize = sizeof(DOCINFO);
- di.lpszDocName = "OnPrintSamplePrn1";
- dc.StartDoc(&di);
- dc.StartPage();
- dc.TextOut(42,42,"hello world for printer 1");
- dc.EndPage();
- dc.EndDoc();
- // Restore former printer
- m_prn_setting1.RestorePrinter();
- }
- void CPrnsetupDlg::OnPrintSamplePrn2()
- {
- // make m_prn_setting2 the MFC standard printer
- m_prn_setting2.SetThisPrinter();
- // Get DC of actual standard printer
- CDC dc;
- AfxGetApp()->CreatePrinterDC(dc);
- DOCINFO di;
- ZeroMemory(&di,sizeof(DOCINFO));
- di.cbSize = sizeof(DOCINFO);
- di.lpszDocName = "OnPrintSamplePrn2";
- dc.StartDoc(&di);
- dc.StartPage();
- dc.TextOut(42,42,"hello world for printer 2");
- dc.EndPage();
- dc.EndDoc();
- // Restore former printer
- m_prn_setting2.RestorePrinter();
- }
- void CPrnsetupDlg::OnGlobalPrinter()
- {
- if( !m_prn_setting1.ValidDevMode()) {
- ShowMessage("Printer1 not set");
- return;
- }
- if(m_prn_setting1.SetPrinterDevice(m_prn_setting1.GetPrinterName()) )
- ShowMessage("Global settings for printer1 changed!");
- else
- ShowMessage("Error changing global printer1 settings");
- }