problem beim drucken
-
Hallo,
warum schmiert mir mein Programm an der Stelle
pDC.Attach(dlgPrint.GetPrinterDC());ab,
wenn ich stattCPrintDialog dlgPrint(FALSE, PD_NOSELECTION, this);CPrintDialog dlgPrint(TRUE, PD_NOSELECTION, this);schreibe?
void CEnglsih_v2View::OnVokabelnButtonPrintToLearn() { CPrintDialog dlgPrint(FALSE, PD_NOSELECTION, this); if (dlgPrint.DoModal()==IDOK) { CDC pDC; CEnglsih_v2Doc *pDoc=GetDocument(); DOCINFO Print; int pageWidth, pageHeight; CString str; CSize szTemp1; TEXTMETRIC tm; CFont font240Bold; pDC.Attach(dlgPrint.GetPrinterDC()); Print.cbSize = sizeof(Print); Print.lpszDocName = TEXT("Dateiliste"); Print.lpszOutput = NULL; Print.lpszDatatype = NULL; Print.fwType = NULL; pageWidth = pDC.GetDeviceCaps(HORZSIZE); pageHeight = pDC.GetDeviceCaps(VERTSIZE); //Schriftarten defienieren //BOOL CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, int nWeight, // BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, // BYTE nOutPrecision, BYTE nClipPrecision, // BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename ); font240Bold.CreateFont(100,0,0,0,700, FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS, "Times New Roman"); if(pDC.StartDoc(&Print)) { pDC.StartPage(); // MapMode festlegen pDC.SetMapMode(MM_LOMETRIC); str=pDoc->myVokabelArray[m_intaktuellePositionInArray]->GetEnglish(); szTemp1=pDC.GetTextExtent(str); pDC.TextOut(((pageWidth*10)/2)-(szTemp1.cx/2),-500,str); pDC.EndPage(); } pDC.EndDoc(); return; } }
-
Weil durch dieses Flag nur der Print Setup Dialog aufgerufen wird und kein DC erzeugt wird!
Es steht doch auch entsprechend in der Doku:
http://msdn2.microsoft.com/en-us/library/32762a1z(VS.80).aspxNote that when you call the constructor with bPrintSetupOnly set to FALSE, the PD_RETURNDC flag is automatically used. After calling DoModal, GetDefaults, or GetPrinterDC, a printer DC will be returned in m_pd.hDC. This DC must be freed with a call to DeleteDC by the caller of CPrintDialog.
In anderen Worten. Möchtest Du dennoch einen DC, dann setze auch das Flag PD_RETURNDC.
CPrintDialog dlgPrint(TRUE, PD_NOSELECTION|PD_RETURNDC, this);