How to use CPrintDialog to realize printing function

Source: Internet
Author: User

Add the following sections to your program

Treat DC1 as device Content.

You print it. Be careful not to draw the wrong place.

Change the page yourself.

What's more, the OnPrint or OnDraw member functions of the Callable window are printed directly. You don't have to do the spacing.

But don't forget to change the page.

// 打印
// 建立打印对话框对象
CPrintDialog
d1(FALSE,PD_ALLPAGES|PD_ALLPAGES|PD_NOPAGENUMS,NULL);
HDC dc1;
if(d1.DoModal()==IDOK){
// 返回一个打印DC句柄
dc1=d1.GetPrinterDC();
// 启动打印工作
StartDoc(dc1,&docin);
// 一页开始
StartPage(dc1);
dc1.textout(.....)
dc1.draw(....)
....
// 一页结束
EndPage(dc1);
可以有多个StartPage(dc1)
...
EndPage(dc1)
// 终止打印工作
EndDoc(dc1);
// 删除句柄
if(DeleteDC(dc1)){
return TRUE;
}else{
出错信息
EndDoc(dc1);
// 删除句柄
if(DeleteDC(dc1)){
return TRUE;
}else{
出错信息
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.