请教,基于对话框的程序要打印,如何实现?

jiva12 2003-10-16 10:25:48
如题,做过的和有经验的老大,给指条明路吧。
最好是保姆型的代码,马上就能用上的,我急用。谢谢。
...全文
27 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiva12 2003-10-18
  • 打赏
  • 举报
回复
好的,多谢 idAnts(你才无聊呢) ,讲的非常详细,谢谢,我这两天忙着编程,没空来csdn,其实什么都是自己摸索出来的,那个问题我已经解决了。无论无何,对这种保姆精神,我一定要给分。
smallsix 2003-10-17
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc.asp?id=314

自己看吧!
idAnts 2003-10-17
  • 打赏
  • 举报
回复
//按下print按钮的函数
void CPrintDlgDlg::OnPrint()
{
CString szContents;
//IDC_EDIT1为一个Edit控件
GetDlgItemText( IDC_EDIT1, szContents );
HDC hdcPrn ;
CPrintDialog *printDlg =
new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1;
printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1;
printDlg->DoModal();
hdcPrn = printDlg->GetPrinterDC();
if (hdcPrn != NULL)
{
CDC *pDC = new CDC;
pDC->Attach (hdcPrn);
pDC->StartDoc("My Printer Dialog");
pDC->StartPage();
SetPrinterSettings(pDC, hdcPrn);
pDC->TextOut(10, 10, szContents);
pDC->EndPage();
pDC->EndDoc();
pDC->Detach();
delete pDC;
}
delete printDlg;
}


void CPrintDlgDlg::SetPrinterSettings(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) ;
}

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧