Printing In MFC Application(在 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 应用程序中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MFC 应用程序中打印
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
