怎样在基于对话框的程序中加入打印和打印预览功能,迫切等待,要不就无法回家过年了!! 看看深入浅出MFC啊!这里怎么教你? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.vckbase.com/sourcecode/打印。能回家过年?无限羡慕当中.......... void CMyDialog::OnPrintBuf() { char pbuf[100] = "Hello World."; HDC hdcPrn ; // Instantiate a CPrintDialog. CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL); // Initialize some of the fields in PRINTDLG structure. printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1; printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1; // Display Windows print dialog box. printDlg->DoModal(); // Obtain a handle to the device context. hdcPrn = printDlg->GetPrinterDC(); if (hdcPrn != NULL) { CDC *pDC = new CDC; pDC->Attach (hdcPrn); // attach a printer DC pDC->StartDoc("test"); // begin a new print job // for Win32 use // CDC::StartDoc(LPDOCINFO) override pDC->StartPage(); // begin a new page SetPrintAlign(pDC, hdcPrn);// set the printing alignment pDC->TextOut(10, 10, pbuf);// 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; } void CMyDialog::SetPrintAlign(CDC *pDC, HDC hdcPrn) { short cxPage, cyPage; cxPage = ::GetDeviceCaps (hdcPrn, HORZRES) ; cyPage = ::GetDeviceCaps (hdcPrn, VERTRES) ; pDC->SetMapMode (MM_ISOTROPIC) ; pDC->SetWindowExt ( 1000, 1000) ; pDC->SetViewportExt (cxPage / 2, -cyPage / 2) ; pDC->SetViewportOrg (cxPage / 2, cyPage / 2) ; pDC->SetTextAlign (TA_BASELINE | TA_CENTER) ; } [百分求助]勾住其他线程WM_KILLFOCUS消息 帮顶有分啊 VC6。0中的工具栏对应是的什么样的结构体 奇怪,为何我用GetCommState()获取LPT1信息会出错? 关于绘图的巨难问题!!! service安装问题 国庆已过,大家过得好吗 100分的问题!十万火急! 我要杀掉MFC恶心的图标!高手指点! 在64位系统上如何进行串口通信 大神们帮帮忙,最近在做课设,急需请教,将不胜感激 ODBC编程,网络不通时弹出的对话框,如何禁止--105分 哪里有在聊天室里查询对方IP地址和端口号的软件?100分相送!
打印。能回家过年?无限羡慕当中..........
{
char pbuf[100] = "Hello World.";
HDC hdcPrn ; // Instantiate a CPrintDialog.
CPrintDialog *printDlg =
new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL); // Initialize some of the fields in PRINTDLG structure.
printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1;
printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1; // Display Windows print dialog box.
printDlg->DoModal(); // Obtain a handle to the device context.
hdcPrn = printDlg->GetPrinterDC();
if (hdcPrn != NULL)
{
CDC *pDC = new CDC;
pDC->Attach (hdcPrn); // attach a printer DC pDC->StartDoc("test"); // begin a new print job
// for Win32 use
// CDC::StartDoc(LPDOCINFO) override pDC->StartPage(); // begin a new page
SetPrintAlign(pDC, hdcPrn);// set the printing alignment
pDC->TextOut(10, 10, pbuf);// 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;
} void CMyDialog::SetPrintAlign(CDC *pDC, HDC hdcPrn)
{
short cxPage, cyPage; cxPage = ::GetDeviceCaps (hdcPrn, HORZRES) ;
cyPage = ::GetDeviceCaps (hdcPrn, VERTRES) ;
pDC->SetMapMode (MM_ISOTROPIC) ;
pDC->SetWindowExt ( 1000, 1000) ;
pDC->SetViewportExt (cxPage / 2, -cyPage / 2) ;
pDC->SetViewportOrg (cxPage / 2, cyPage / 2) ;
pDC->SetTextAlign (TA_BASELINE | TA_CENTER) ;
}