Solved

HELP!!!! Print Dialog Big Problem

Posted on 1998-08-20
5
394 Views
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__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CServiceDialog dialog


CServiceDialog::CServiceDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CServiceDialog::IDD, pParent)
{
      //{{AFX_DATA_INIT(CServiceDialog)
      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_starttime32=0.0;
      m_endtime12=0.0;
      m_endtime22=0.0;
      m_endtime32=0.0;
      m_hours12=0.0;
      m_hours22=0.0;
      m_hours32=0.0;
      m_price12=0.0;
      m_price22=0.0;
      m_price32=0.0;
      m_qty12=0.0;
      m_qty22=0.0;
      m_qty32=0.0;
      m_tot2=0.0;
      m_totlab2=0.0;
      m_totprice2=0.0;
      m_travel12=0.0;
      m_travel22=0.0;
      m_travel32=0.0;
      m_calldate = time_t(0);
      //}}AFX_DATA_INIT
}


void CServiceDialog::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CServiceDialog)
      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);
      //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CServiceDialog, CDialog)
      //{{AFX_MSG_MAP(CServiceDialog)
      ON_BN_CLICKED(IDC_PAGE2_BUTTON, OnPage2Button)
      ON_BN_CLICKED(IDC_EXIT_BUTTON2, OnExitButton2)
      ON_BN_CLICKED(IDC_CALC_BUTTON, OnCalcButton)
      ON_BN_CLICKED(IDC_PRINT_BUTTON, OnPrintButton)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CServiceDialog message handlers

void CServiceDialog::OnPage2Button()
{
      // TODO: Add your control notification handler code here
      //sets varibles to another page
      UpdateData(TRUE);
      OnOK();
      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_contacts2=m_contacts22;
      Srv2Dlg.m_dates2=m_dates22;
      Srv2Dlg.m_date1s2=m_date1s22;
      Srv2Dlg.m_date12s2=m_date12s22;
      Srv2Dlg.m_date2s2=m_date2s22;
      Srv2Dlg.m_date3s2=m_date3s22;
      Srv2Dlg.m_extension1s2=m_extension1s22;
      Srv2Dlg.m_extension2s2=m_extension2s22;
      Srv2Dlg.m_extension3s2=m_extension3s22;
      Srv2Dlg.m_faxnums2=m_faxnums22;
      Srv2Dlg.m_loanagrees2=m_loanagrees22;
      Srv2Dlg.m_ourponums2=m_ourponums22;
      Srv2Dlg.m_partnum1s2=m_partnum1s22;
      Srv2Dlg.m_partnum2s2=m_partnum2s22;
      Srv2Dlg.m_partnum3s2=m_partnum3s22;
      Srv2Dlg.m_partsused1s2=m_partsused1s22;
      Srv2Dlg.m_partsused2s2=m_partsused2s22;
      Srv2Dlg.m_partsused3s2=m_partsused3s22;
      Srv2Dlg.m_phonenums2=m_phonenums22;
      Srv2Dlg.m_rmas2=m_rmas22;
      Srv2Dlg.m_servpref1s2=m_servpref1s22;
      Srv2Dlg.m_servpref2s2=m_servpref2s22;
      Srv2Dlg.m_servpref3s2=m_servpref3s22;
      Srv2Dlg.m_tech1s2=m_tech1s22;
      Srv2Dlg.m_tech2s2=m_tech2s22;
      Srv2Dlg.m_tech3s2=m_tech3s22;
      Srv2Dlg.m_vendors2=m_vendors22;
      Srv2Dlg.m_starttime1= m_starttime12;
      Srv2Dlg.m_starttime2=m_starttime22;
      Srv2Dlg.m_starttime3=m_starttime32;
      Srv2Dlg.m_endtime1=m_endtime12;
      Srv2Dlg.m_endtime2=m_endtime22;
      Srv2Dlg.m_endtime3=m_endtime32;
      Srv2Dlg.m_hours1=m_hours12;
      Srv2Dlg.m_hours2=m_hours22;
      Srv2Dlg.m_hours3=m_hours32;
      Srv2Dlg.m_price1=m_price12;
      Srv2Dlg.m_price2=m_price22;
      Srv2Dlg.m_price3=m_price32;
      Srv2Dlg.m_qty1=m_qty12;
      Srv2Dlg.m_qty2=m_qty22;
      Srv2Dlg.m_qty3=m_qty32;
      Srv2Dlg.m_tot=m_tot2;
      Srv2Dlg.m_totlab=m_totlab2;
      Srv2Dlg.m_totprice=m_totprice2;
      Srv2Dlg.m_travel1=m_travel12;
      Srv2Dlg.m_travel2=m_travel22;
      Srv2Dlg.m_travel3=m_travel32;      

      Srv2Dlg.DoModal();

}

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



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_totlabour=m_billtime*m_ratelabour;
      m_totinv=m_totparts+m_tottravel+m_totlabour; // calc total invoice

      cout<<m_tottravel;  
      cout<<m_totlabour;
      cout<<m_totinv;
    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.

0
Comment
Question by:lance100
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
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.
http://geocities.com/SiliconValley/Network/9353/


0
 
LVL 8

Expert Comment

by:Answers2000
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
        return;

    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.
    strTitle.LoadString(AFX_IDS_APP_TITLE);

    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;
    Info.m_rectDraw.SetRect(0,0,
                            dc.GetDeviceCaps(HORZRES),
                            dc.GetDeviceCaps(VERTRES));

    OnBeginPrinting(&dc, &Info);                // Call your "Init printing" funtion
    for (UINT page = Info.GetMinPage();
         page <= Info.GetMaxPage() && bPrintingOK;
         page++)
    {
        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
    else
        dc.AbortDoc();                          // abort job.

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

0
 
LVL 8

Expert Comment

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

Expert Comment

by:trestan
ID: 1321087
You are right. I ignored that.
0
 

Author Comment

by:lance100
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.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
Folder Comparison 12 54
Not needed 13 109
x-bar in Google Sheets 2 51
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

17 Experts available now in Live!

Get 1:1 Help Now