打印出了问题,高手来帮忙!
UINT ResultField::PrintThread(LPVOID pParam)
{
ResultField * Re =(ResultField*)pParam;
static DOCINFO di = { sizeof (DOCINFO), "数据打印", NULL } ;
PRINTER_INFO_5 pinfo5[3] ;
DWORD dwNeeded, dwReturned ;
CDC* m_pPrnDC = new CDC;
CString PrintLine;
CString temp;
CFont PrintFont;
CFont *pOldFont;
CPen *oldPen;
CLimitSet *LimitSet = new CLimitSet(); //这是两个对话框类,里面
CConfig * ConfigSet = new CConfig();//是我保存在ini中的东西,取
//了出来。
long LinePosition=100; //打印的行位置
LOGFONT newLogFont=Re->m_Lf;
TEXTMETRIC TextM;
if (EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (LPBYTE) pinfo5,
sizeof (pinfo5), &dwNeeded, &dwReturned))
{
m_pPrnDC->CreateDC (NULL, pinfo5[0].pPrinterName, NULL, NULL) ;
m_pPrnDC->StartDoc(&di);
m_pPrnDC->StartPage();
int nPageHeight=m_pPrnDC->GetDeviceCaps(VERTRES);
int nPageWidth=m_pPrnDC->GetDeviceCaps(HORZRES);
// int LineStart=(MaxLineChar-PrintLine.GetLength())/2;
// m_pPrnDC->TextOut(LineStart*CharWidth,LinePosition,PrintLine);
m_pPrnDC->SetMapMode(MM_ISOTROPIC) ;
m_pPrnDC->SetWindowExt(nPageWidth,nPageHeight) ;
m_pPrnDC->SetViewportExt(nPageWidth/2, nPageHeight) ;
m_pPrnDC->SetViewportOrg(nPageWidth/2,0) ;
newLogFont.lfHeight=400;//标题打印 大号字体
PrintFont.CreateFontIndirect(&newLogFont);
pOldFont=m_pPrnDC->SelectObject(&PrintFont);
m_pPrnDC->GetTextMetrics(&TextM);
int LineHeight=(unsigned short)TextM.tmHeight;
int CharWidth=(unsigned short)TextM.tmAveCharWidth;
int MaxLineChar=nPageWidth/CharWidth-8;
LinePosition+=LineHeight;
temp=ConfigSet->m_ReportHead; //我跟踪了得到字符串对但是就是
//打不出来
// temp="居中打印测试"; //直接付值就能打出来。
PrintLine=temp;
int oldAlign=m_pPrnDC->GetTextAlign();
m_pPrnDC->SetTextAlign (TA_BASELINE | TA_CENTER) ;
m_pPrnDC->TextOut(0,LinePosition,PrintLine);
m_pPrnDC->SetTextAlign(oldAlign);
m_pPrnDC->SelectObject(pOldFont);
m_pPrnDC->GetTextMetrics(&TextM);
LineHeight = (unsigned short)TextM.tmHeight;
CharWidth = (unsigned short)TextM.tmAveCharWidth;
MaxLineChar = nPageWidth/CharWidth-8;
LinePosition += LineHeight;
m_pPrnDC->TextOut(0,LinePosition,PrintLine);
LinePosition+=LineHeight;
m_pPrnDC->TextOut(0,LinePosition,PrintLine);
m_pPrnDC->EndPage();
m_pPrnDC->EndDoc();
m_pPrnDC->DeleteDC();
}
delete ConfigSet;
delete LimitSet;
return 0;
}
请高手指点!