Home > Software engineering >  Dialog box using CPrintDialog classes, jammed
Dialog box using CPrintDialog classes, jammed

Time:09-19

 void CPrintfFileTextDlg: : OnBnClickedButton1 () 
{
CPrintDialog printDlg (FALSE);
//get the default print attributes,
print Windows not being displayed//printDlg GetDefaults ();
//or from the user access to
If (printDlg DoModal ()==IDCANCEL)
return;
The CDC dc;
if (! Dc. Attach (printDlg GetPrinterDC ()))
{
MessageBox (_T (" found no printer!" ), _T (" tip "));
return;
}
Dc. M_bPrinting=TRUE;
DOCINFO di;
//initialize the print documents detailed information
: : ZeroMemory (& amp; Di, sizeof (DOCINFO));
Di. CbSize=sizeof (DOCINFO);
Di. LpszDocName=_T (" label printing ");
BOOL bPrintingOK=dc. StartDoc (& amp; Di);//start a new print job
//get print range and stored in the object of CPrintInfo
CPrintInfo Info;
Info. SetMaxPage (1); Only one page////get all the pixels
Int maxw=dc. GetDeviceCaps (HORZRES);
Int maxh=dc. GetDeviceCaps (VERTRES);
//set the paper print size
Info. M_rectDraw. SetRect (0, 0, maxw maxh);
//
For (UINT page=Info. GetMinPage (); Page & lt;=Info. GetMaxPage () & amp; &
BPrintingOK; Page++)
{
Dc. StartPage ();//start a new page
Info. M_nCurPage=page;
CImage Img.
Img. Load (_T (" d://22. PNG "));
HBITMAP hBitm;
HBitm=Img. Detach ();//separation bitmap handle
CBitmap bitmap.
Bitmap. The Attach (hBitm);//attach a bitmap handle
BITMAP bm.
Bitmap. GetBitmap (& amp; Bm);
Int w=bm. BmWidth;
Int h=bm. BmHeight;
//create a memory device context
The CDC memDC;
MemDC. CreateCompatibleDC (& amp; Dc);
CBitmap * pBmp=memDC. SelectObject (& amp; Bitmap);
MemDC. SetMapMode (dc) GetMapMode ());
Dc. SetStretchBltMode (HALFTONE);
//now stretched to the maximum width of the page
Dc. StretchBlt (0, 0, maxw maxh, & amp; MemDC, 0, 0, w, h, SRCCOPY);
//clean up
MemDC. SelectObject (pBmp);
BPrintingOK=(dc EndPage () & gt; 0);//the end page
}
If (bPrintingOK)
Dc. EndDoc ();//end print job
The else
Dc. AbortDoc ();//suspended card

At the start of print jobs there, VS all CARDS collapse, nasty, how to solve

CodePudding user response:

The CDC: : EndPage Return Value Greater than or equal to zero if successful ;

BPrintingOK=(dc EndPage () & gt;= 0);//the end page