?
Solved

saving info from CPrintDlg

Posted on 1997-03-01
1
Medium Priority
?
339 Views
Last Modified: 2013-11-20
Hi...
Basically I need to use CPrintDialog once to find which printer will be used.  I then want to save this info and when the next time my program is run, load this info, and then just skip (or at least not display) the CPrintDialog.
I guess I need to know what data to save and then how to use it after loading it back up.

My current code is this:


void CPrintdDlg::OnButtonPrint()
{
// TODO: Add your control notification handler code here

      
int i, i2;
BOOL truth = TRUE;      
CString string1, string2, string3;
CStdioFile cfile;
CFileException fileException;
HDC hdcPrn;

if(pstring.IsEmpty() != 0)
{
   i = MessageBox("You have not selected a file!", "Stop!",        MB_OK);
   return;
}

if ( !cfile.Open( pstring, CFile::modeRead, &fileException ))
{
   i = MessageBox("There is no such file!!!", "Error", MB_OK);
      
   TRACE( "Can't open file %s, error = %u\n",
                pstring, fileException.m_cause );
return;
}

// THIS IS THE CODE THAT NEEDS TO BE ALTERED
CPrintDialog *printDlg = new CPrintDialog(FALSE,PD_ALLPAGES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION);

printDlg->DoModal();

hdcPrn = printDlg->GetPrinterDC();
  if (hdcPrn != NULL)
  {
      CDC *pDC = new CDC;
      pDC->Attach (hdcPrn);      // attach a printer DC
      TEXTMETRIC tm;
      pDC->SetMapMode(MM_TEXT);
      pDC->GetTextMetrics(&tm);
     int width1 = pDC->GetDeviceCaps (PHYSICALWIDTH);
//     int vertical1 = pDC->GetDeviceCaps(VERTSIZE);
    vertical1 = pDC->GetDeviceCaps(PHYSICALHEIGHT);
    int paper_length = vertical1 / (tm.tmHeight     + tm.tmExternalLeading);
    int paper_width  = width1 / tm.tmMaxCharWidth;

    i = 0;

    pDC->StartDoc(pstring);     // begin a new print job




   while(truth == TRUE)
   {
        pDC->StartPage();          // begin a new page
        i = 0;
        string1.Empty();
        string2.Empty();
                  string3.Empty();
                  while( (i<paper_length-4) && (truth == TRUE) )
                  {
                        i++;
                        string2.Empty();
                        
                        if(string3.IsEmpty() == 1)
                              truth = cfile.ReadString(string2);
                        else
                        {
                              string2 = string3;
                              string1.Empty();
                              string3.Empty();
                        }
                        i2 = string2.GetLength();



                        if(i2 < paper_width-2)
                        {
                              pDC->TextOut(0, (i*(tm.tmHeight+tm.tmExternalLeading)), string2);// write the string in pbuf
                              string3.Empty();
                        }
                        else
                        {
                              
                              string1 = string2.Left(paper_width-2);
                              string3 = string2.Right(string2.GetLength() - paper_width+2);
                              

                              pDC->TextOut(0, (i*(tm.tmHeight+tm.tmExternalLeading)), string1);// write the string in pbuf

                        }
                        
                  }

                  pDC->EndPage();            // end a page

            }


        pDC->EndDoc();             // end a print job
        pDC->Detach();             // detach the printer DC
        delete pDC;
            delete printDlg;
      
      }
0
Comment
Question by:nemesis011397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1300318
What you need to save are three strings,

1. the name of the currently selected printer driver, CPrintDialog::GetDriverName();
2. the name of the currently selected printer device, CPrintDialog::GetDeviceName();
3. the name of the currently selected printer port, CPrintDialog::GetPortName().

I suggest you save them into a INI file by using ::WritePrivateProfileString() or CWinApp::WriteProfileString().

The next time, you can read the three strings from the INI file and call the following function to create the printer DC.
BOOL CDC::CreateDC( LPCSTR lpszDriverName, LPCSTR lpszDeviceName, LPCSTR lpszOutput, const void FAR* lpInitData );
Then you can use the DC to print as you have done.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

741 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