nemesis011397
asked on
saving info from CPrintDlg
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_ALLP AGES | 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(VERTSIZ E);
vertical1 = pDC->GetDeviceCaps(PHYSICA LHEIGHT);
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.tmExter nalLeading )), string2);// write the string in pbuf
string3.Empty();
}
else
{
string1 = string2.Left(paper_width-2 );
string3 = string2.Right(string2.GetL ength() - paper_width+2);
pDC->TextOut(0, (i*(tm.tmHeight+tm.tmExter nalLeading )), 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;
}
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_ALLP
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(VERTSIZ
vertical1 = pDC->GetDeviceCaps(PHYSICA
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.tmExter
string3.Empty();
}
else
{
string1 = string2.Left(paper_width-2
string3 = string2.Right(string2.GetL
pDC->TextOut(0, (i*(tm.tmHeight+tm.tmExter
}
}
pDC->EndPage(); // end a page
}
pDC->EndDoc(); // end a print job
pDC->Detach(); // detach the printer DC
delete pDC;
delete printDlg;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.