-
Help Please
hi,
i am new to VC++ Environment.
my problem is - i have to generate pay slips for the employees. when the user selects the menu "Prepare Payslips", one dialog box will be displayed and the user has to enter the employee number. when the user enters the emp number, the Salary related information will be displayed in the dialog box edit controls. if the user selects the print button, then a report has to be generated and printed in the printer.
how to do printing from the Dialog Class. i have to do it immediately. please help
Thanks in Advance,
Kalyan
-
Re: Help Please
Hi Kalyan,
to print from the Dialog Class try this:
1. First create a CPrintDialog
2. If it is closed with the OK-Button attach its PrinterDC to a CDC
3. Create a DOCINFO structure and fill it with printinformations
4. Start printing using functions like StartDoc/EndDoc, StartPage/EndPage...
I prepared a listing, demonstrating this. I tested it in a dialog-based, MFC-based application (Microsoft Visual C++ 6.0). Please write a short answer, if you had success.
Good Luck !!!
Peter
void CExampleDlg::OnPrint()
{
// Printerdialog
CPrintDialog d(FALSE,PD_ALLPAGES,this);
if(d.DoModal()==IDOK) //if the OK-Button was pressed
{
// Make a printer-device-context
CDC dc;
dc.Attach(d.GetPrinterDC());
// Printinformations
DOCINFO myPrint;
myPrint.cbSize=sizeof(myPrint);
myPrint.lpszDocName="Report";
myPrint.lpszOutput=NULL;
myPrint.lpszDatatype=NULL;
myPrint.fwType=NULL;
// Start printing
if(dc.StartDoc(&myPrint)>=0)
{
dc.StartPage();
// Create and Select a Pen
CPen MyPen(PS_SOLID,0,RGB(0,0,0)),*pOldPen;
pOldPen=dc.SelectObject(&MyPen);
// Begin drawing something
dc.Rectangle(0,0,500,500);
dc.MoveTo( 0, 0);
dc.LineTo(500, 500);
dc.MoveTo( 0, 500);
dc.LineTo(500, 0);
// End drawing something
// Select old pen
dc.SelectObject(pOldPen);
dc.EndPage();
dc.EndDoc();
}
// Erase printer-device-context
dc.DeleteDC();
}
}
-
Re: Help Please
Hi Peter,
Thank you. i'm able to print now. the code is working fine. once again thanks a lot.
Regards,
Kalyan