HELP!!!! Print Dialog Big Problem

Posted on 1998-08-20
Last Modified: 2013-11-20
I am having a difficult time learning how to print the info out that need.  Can any find it in there heart to help out struggling beginner programmer like myself.  I have a dialog box(below) which I want printed.  I struggled with this for three days and I can't figure it out.  If someone is nice enough can they either write the code for me or explain in detail how to do it. Also can you referr to my variable names show I can understand more clearly.
Thank you so much for the help I that I need so much.

// ServiceDialog.cpp : implementation file

#include "stdafx.h"
#include "afxdlgs.h"      
#include "menu.h"
#include "ServiceDialog.h"
#include "Service2Dialog.h"
#include "SaveDialog.h"
#include "iostream.h"
#include "afxwin.h"
#include "stdio.h"
#include "process.h"
#include "dos.h"
#include <fstream.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

// CServiceDialog dialog

CServiceDialog::CServiceDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CServiceDialog::IDD, pParent)
      m_billtravel = 0.0;
      m_totinv = 0.0;
      m_totlabour = 0.0;
      m_totparts = 0.0;
      m_tottravel = 0.0;
      m_billtime = 0.0;
      m_ratelabour = 60.0;
      m_ratetravel = 60.0;
      m_custnum = _T("");
      m_ordernum = _T("");
      m_address = _T("");
      m_assigned = _T("");
      m_billcode = _T("");
      m_company = _T("");
      m_contact = _T("");
      m_contract = _T("");
      m_custponum = _T("");
      m_custref = _T("");
      m_faxnum = _T("");
      m_makemod = _T("");
      m_onsite = FALSE;
      m_opersys = _T("");
      m_phonenum = _T("");
      m_problem = _T("");
      m_promised = _T("");
      m_response = _T("");
      m_serialnum = _T("");
      m_servtype = _T("");
      m_siteaddress = _T("");
      m_software = _T("");
      m_status = _T("");
      m_urgency = _T("");
      m_version = _T("");
      m_waitparts = _T("");
      //varialbles to hold info from page 2
      //does not need to be printed!!
      m_contacts22 = _T("");
      m_dates22 = _T("");
      m_date1s22 = _T("");
      m_date12s22 = _T("");
      m_date2s22 = _T("");
      m_date3s22 = _T("");
      m_extension1s22 = _T("");
      m_extension2s22 = _T("");
      m_extension3s22 = _T("");
      m_faxnums22 = _T("");
      m_loanagrees22 = _T("");
      m_ourponums22 = _T("");
      m_partnum1s22 = _T("");
      m_partnum2s22 = _T("");
      m_partnum3s22 = _T("");
      m_partsused1s22 = _T("");
      m_partsused2s22 = _T("");
      m_partsused3s22 = _T("");
      m_phonenums22 = _T("");
      m_rmas22 = _T("");
      m_servpref1s22 = _T("");
      m_servpref2s22 = _T("");
      m_servpref3s22 = _T("");
      m_tech1s22 = _T("");
      m_tech2s22 = _T("");
      m_tech3s22 = _T("");
      m_vendors22 = _T("");
      m_starttime12 = 0.0;
      m_starttime22 = 0.0;
      m_calldate = time_t(0);

void CServiceDialog::DoDataExchange(CDataExchange* pDX)
      DDX_Text(pDX, IDC_BILLTRAVEL_EDIT, m_billtravel);
      DDX_Text(pDX, IDC_TOTINV_EDIT, m_totinv);
      DDX_Text(pDX, IDC_TOTLABOUR_EDIT, m_totlabour);
      DDX_Text(pDX, IDC_TOTPARTS_EDIT, m_totparts);
      DDX_Text(pDX, IDC_TOTTAVEL_EDIT, m_tottravel);
      DDX_Text(pDX, IDC_BILLTIME_EDIT, m_billtime);
      DDX_Text(pDX, IDC_RATELABOUR_EDIT, m_ratelabour);
      DDX_Text(pDX, IDC_RATETRAVEL_EDIT, m_ratetravel);
      DDX_Text(pDX, IDC_CUSTNUM_EDIT, m_custnum);
      DDX_Text(pDX, IDC_ORDERNUM_EDIT, m_ordernum);
      DDX_Text(pDX, IDC_ADDRESS_EDIT, m_address);
      DDX_CBString(pDX, IDC_ASSIGNED_COMBO, m_assigned);
      DDX_CBString(pDX, IDC_BILLCODE_COMBO, m_billcode);
      DDX_Text(pDX, IDC_COMPANY_EDIT, m_company);
      DDX_Text(pDX, IDC_CONTACT_EDIT, m_contact);
      DDX_Text(pDX, IDC_CONTRACT_EDIT, m_contract);
      DDX_Text(pDX, IDC_CUSTPONUM_EDIT, m_custponum);
      DDX_Text(pDX, IDC_CUSTREF_EDIT, m_custref);
      DDX_Text(pDX, IDC_FAXNUM_EDIT, m_faxnum);
      DDX_Text(pDX, IDC_MAKEMOD_EDIT, m_makemod);
      DDX_Check(pDX, IDC_ONSITE_CHECK, m_onsite);
      DDX_CBString(pDX, IDC_OPERSYS_COMBO, m_opersys);
      DDX_Text(pDX, IDC_PHONENUM_EDIT, m_phonenum);
      DDX_Text(pDX, IDC_PROBLEM_EDIT, m_problem);
      DDX_Text(pDX, IDC_PROMISED_EDIT, m_promised);
      DDX_Text(pDX, IDC_RESPONSE_EDIT, m_response);
      DDX_Text(pDX, IDC_SERIALNUM_EDIT, m_serialnum);
      DDX_CBString(pDX, IDC_SERVTYPE_COMBO, m_servtype);
      DDX_Text(pDX, IDC_SITEADDRESS_EDIT, m_siteaddress);
      DDX_Text(pDX, IDC_SOFTWARE_EDIT, m_software);
      DDX_CBString(pDX, IDC_STATUS_COMBO, m_status);
      DDX_CBString(pDX, IDC_URGENCY_COMBO, m_urgency);
      DDX_Text(pDX, IDC_VERSION_EDIT, m_version);
      DDX_CBString(pDX, IDC_WAITPARTS_COMBO, m_waitparts);
      DDX_Text(pDX, IDC_CALLDATE_EDIT, m_calldate);

BEGIN_MESSAGE_MAP(CServiceDialog, CDialog)

// CServiceDialog message handlers

void CServiceDialog::OnPage2Button()
      // TODO: Add your control notification handler code here
      //sets varibles to another page
      CService2Dialog Srv2Dlg;
      Srv2Dlg.m_calldate2 = m_calldate;
      Srv2Dlg.m_custnum2 = m_custnum;
      Srv2Dlg.m_address2 =m_address;
      Srv2Dlg.m_assigned2 =m_assigned;
      Srv2Dlg.m_company2 =m_company;
      Srv2Dlg.m_contact2 =m_contact;
      Srv2Dlg.m_contract2 =m_contract;
      Srv2Dlg.m_custponum2 =m_custponum;
      Srv2Dlg.m_custref2 =m_custref;
      Srv2Dlg.m_faxnum2 =m_faxnum;
      Srv2Dlg.m_makemod2 =m_makemod;
      Srv2Dlg.m_opersys2 =m_opersys;
      Srv2Dlg.m_ordernum2 =m_ordernum;
      Srv2Dlg.m_phonenum2 =m_phonenum;
      Srv2Dlg.m_problem2 = m_problem;
      Srv2Dlg.m_promised2 = m_promised;
      Srv2Dlg.m_response2 = m_response;
      Srv2Dlg.m_serialnum2 =m_serialnum;
      Srv2Dlg.m_servtype2 = m_servtype;
      Srv2Dlg.m_siteaddress2 =m_siteaddress;
      Srv2Dlg.m_software2 = m_software;
      Srv2Dlg.m_status2 = m_status;
      Srv2Dlg.m_urgency2 = m_urgency;
      Srv2Dlg.m_version2 = m_version;
      Srv2Dlg.m_waitparts2 = m_waitparts;
      Srv2Dlg.m_billcode2 = m_billcode;
      Srv2Dlg.m_onsite2 = m_onsite;

      Srv2Dlg.m_starttime1= m_starttime12;



void CServiceDialog::OnExitButton2()
      // TODO: Add your control notification handler code here
      //connects to another dialog box to save info
      CSaveDialog SaveDlg;

void CServiceDialog::OnCalcButton()
      // TODO: Add your control notification handler code here
      //does simple calulates in my dialog

      UpdateData(TRUE); // get data from controls
      m_tottravel=m_billtravel*m_ratetravel; //calculate total labour
      m_totinv=m_totparts+m_tottravel+m_totlabour; // calc total invoice

    UpdateData(FALSE); // send data to controls


void CServiceDialog::OnPrintButton()
      // TODO: Add your control notification handler code here
      //Here is the print button which I want to print from.
      //Please place the code here.

Question by:lance100
  • 2
  • 2

Accepted Solution

trestan earned 100 total points
ID: 1321084
You must have a lot of edit box in your dialog interface. First, in your void CServiceDialog::OnPage2Button(), you should put the OnOk(); at the end of the function. Otherwise the values can not be assigned. To print the values (That is what you want to print, right?), you can use textout or other output functions of CDC under the OnPrint() function.
If you want the codes, please email me your project, then I can add the codes for you.


Expert Comment

ID: 1321085
You can use UpdateData to force the latest data to be retrieved (it won't be unless they press OK by default).

Now to printing...

In a Doc/View application MFC does most of the work for you.  Unfortunately in a dialog based application, you need to write code to initialize the printer, etc.

When printing you "draw" to the printer using an HDC (which is encapsulated in the MFC class CDC)

Here is a sample, I've sorta adapted for your app

void CServiceDialog::OnPrintButton()
    CDC dc;
    CPrintDialog printDlg(FALSE);

//---> you can setup members of printDlg here to allow
//     printing of a selection, or to allow only the "all pages"
//     option, m_pd member of printDlg contains most of the
//     options, m_pd.Flags is the main one you're probably
//     interested in

    if (printDlg.DoModal() == IDCANCEL)         // Get printer settings from user

    dc.Attach(printDlg.GetPrinterDC());         // Attach a printer DC
    dc.m_bPrinting = TRUE;

    CString strTitle;                           // Get the application title
//---> change this if you want to print under a differnt
//     title, this is used for the print job name.

    DOCINFO di;                                 // Initialise print document details
    ::ZeroMemory (&di, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    di.lpszDocName = strTitle;

    BOOL bPrintingOK = dc.StartDoc(&di);        // Begin a new print job

    // Get the printing extents and store in the m_rectDraw field of a
    // CPrintInfo object
    CPrintInfo Info;

    OnBeginPrinting(&dc, &Info);                // Call your "Init printing" funtion
    for (UINT page = Info.GetMinPage();
         page <= Info.GetMaxPage() && bPrintingOK;
        dc.StartPage();                         // begin new page
        Info.m_nCurPage = page;

//---> add your code to "draw" here
//     you may prefer to put it in another function and call that
//     for example,
         dc.TextOut( 0, 0, "Hello world" ) ;
//     will "draw" this phrase at the top left of the page
        bPrintingOK = (dc.EndPage() > 0);       // end page
    OnEndPrinting(&dc, &Info);                  // Call your "Clean up" funtion

    if (bPrintingOK)
        dc.EndDoc();                            // end a print job
        dc.AbortDoc();                          // abort job.

    dc.Detach();                                // detach the printer DC


Expert Comment

ID: 1321086
trestan, no offence, but he needs to create the printer DC, OnPrint is only called for Doc/View applications.

Expert Comment

ID: 1321087
You are right. I ignored that.

Author Comment

ID: 1321088
I am getting 2 errors when I but in the code.
1. the OnBeginPrinting is not declared
2. the OnEnd Printing is not declared

can you tell me what to do and what to place in the functions if I have to make them.
I am a beginner at this and I need help.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 85
Perl Awk Need Help 3 109
viewing source code from eclipse 13 88
fizzArray  challenge 1 58
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now