在MFC应用程序中打印 [英] Printing In MFC Application

查看:93
本文介绍了在MFC应用程序中打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用基于MFC对话框的应用程序打印文档?我做了一个打印按钮.单击此按钮后,我要打印一些文档或文本.

How can I print a document using MFC Dialog Based Application? I have made a print button. After clicking on this button, I want print of some document or some text.

推荐答案

您可以创建一个不可见的CHtmlEditCtrl控件,并使用SetDocumentHTML(LPCTSTR)方法将文本加载到其中,然后调用PrintDocument()方法.

You can create an invisble CHtmlEditCtrl control and load your text to it with SetDocumentHTML(LPCTSTR) method and then call PrintDocument() method.

void WaitForComplete(IHTMLDocument2* document)
{
    BSTR ready;
    document->get_readyState(&ready);
    while(wcscmp(ready, L"complete"))
    {
        AfxPumpMessage();
        document->get_readyState(&ready);
    };
}

void CPrintInMFCDialogBasedAppDlg::OnBnClickedPrint()
{
    CHtmlEditCtrl PrintCtrl;
    if(!PrintCtrl.Create(NULL, WS_CHILD, CRect(0, 0, 0, 0), this, 1))
    {
        ASSERT(FALSE);
        return; // Error!
    }
    CComPtr<IHTMLDocument2> document;
    PrintCtrl.GetDocument(&document);
    WaitForComplete(document);
    PrintCtrl.SetDocumentHTML(_T("Hello!<BR>It is <B>my first</B> print!"));
    WaitForComplete(document);
    PrintCtrl.PrintDocument();
}

这篇关于在MFC应用程序中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆