问题描述
大家好,
我之所以发布此问题,是因为我被困在从资源加载 .rtf 文件并在打印预览之前更改某些值"的情况下.
- .rtf 文件的内容可能包含一些要替换的变量(即: @单价@ 或 @日期和时间@ 或介于两个 @ 之间的内容).
-仅当从主菜单中单击"打印预览"时, .rtf 文件的内容才可见.
-主应用程序是 SDI 应用程序,其主视图类为CFormView
类型,因此 .rtf 文件的内容将不可见.
- @单价@ 和 @日期和时间@ 将替换为从CFormView
主视图中的某些CEdit
编辑框中检索的值.
-如果我有:m_EdtUnitPrice = "$200.00"
和m_EdtDateAndTime = "09/28/2012"
和:
- .rtf文件之前的内容为:
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla @Unit Price @ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla @Date a Time @@ b bla bla bla bla bla bla bla bla bla bla.
因此,在主菜单中单击"打印预览"后:
- .rtf文件之后的内容将是:
<$ 200.00 bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 09/28/2012 bla bla bla bla bla bla bla bla bla bla bla bla bla.
加载代码:
Hi everybody,
I am posting this question because I am stuck on "Loading an .rtf file from the resources and change some values before Print-Preview it".
- The content of the .rtf file may contain some variables to replace (i.e: @Unit Price@ or @Date and Time@ or something between the two @).
- The content of the .rtf file will be visible only when you click "Print Preview" from the main menu.
- The main application is an SDI app with a main view class of a CFormView
type, so the content of the .rtf file will not be visible.
- @Unit Price@ and @Date and Time@ will be replaced with values retrieved from some CEdit
edit boxes from the main CFormView
view.
- If I have: m_EdtUnitPrice = "$200.00"
and m_EdtDateAndTime = "09/28/2012"
and:
- The content of the .rtf file Before was:
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla @Unit Price@ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla @Date an Time@ bla bla bla bla bla bla bla bla bla bla bla bla bla.
So after I click "Print Preview" from the main menu:
- The content of the .rtf file After will be:
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla $200.00 bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 09/28/2012 bla bla bla bla bla bla bla bla bla bla bla bla bla.
The Load Code:
void CGLVImpressionView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
HRSRC hRsrc = ::FindResource(NULL, _T("Print Preview.rtf"), _T("RTF"));
if (hRsrc == NULL)
return;
HGLOBAL hGlobal = ::LoadResource(NULL, hRsrc);
if (hGlobal == NULL)
return;
LPTSTR pData = (LPTSTR)::LockResource(hGlobal);
if (pData == NULL)
return;
DWORD dwSize = ::SizeofResource(NULL, hRsrc);
if (dwSize == 0)
return;
...
// Whats next !?
// How to replace the pData content variables: @Unit Price@ and @Date an Time@ !?
// How to make the loaded .rtf show in Print Preview !?
...
}
谢谢您的理解.
Thank you for your understanding.
推荐答案
void CGLVImpressionView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
HRSRC hRsrc = ::FindResource(NULL, _T("Print Preview.rtf"), _T("RTF"));
if (hRsrc == NULL)
return;
HGLOBAL hGlobal = ::LoadResource(NULL, hRsrc);
if (hGlobal == NULL)
return;
LPTSTR pData = (LPTSTR)::LockResource(hGlobal);
if (pData == NULL)
return;
DWORD dwSize = ::SizeofResource(NULL, hRsrc);
if (dwSize == 0)
return;
...
// Whats next !?
// How to replace the pData content variables: @Unit Price@ and @Date an Time@ !?
// How to make the loaded .rtf show in Print Preview !?
...
}
谢谢您的理解.
Thank you for your understanding.
这篇关于从资源加载.rtf,并在打印预览之前更改一些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!