|
//***************************************************************************************
// I want to draw the RichTextControl content in a specified rectangle on my printing page
// (as i done with editbox control) using FormatRange function with the different
// Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this function ?..
//***************************************************************************************
//The partial code
//RTCtrlPrint1View.h
public:
CRTCtrlPrint1Doc* GetDocument();
//My*************************************
void RTCtrlCreate();
void DrawRichText(CDC *pDC);
void DrawEditText(CDC *pDC);
CRichEditCtrl m_redit;
CRect m_redRect;
CEdit m_edit;
CRect m_edRect;
UINT r;
CFont font;
//**************************************
//RTCtrlPrint1View.cpp
void CRTCtrlPrint1View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
/*B**********************************************/
//edith box displaytext font
font.CreateFont(14,0,0,0,FW_NORMAL,FALSE,FALSE,
0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_MODERN,"Arial");
r=14;
m_edRect = CRect(50*r,-100*r,240*r,-700*r);
m_redRect = CRect(250*r,-100*r,750*r,-700*r);
CSize sizeTotal;
sizeTotal.cx = 850*r;
sizeTotal.cy = 1100*r;
SetScrollSizes(MM_TWIPS, sizeTotal); //MM_TWIPS
RTCtrlCreate();
/*E**********************************************/
}
void CRTCtrlPrint1View::OnDraw(CDC* pDC)
{
CRTCtrlPrint1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/*B**********************************************/
pDC->Rectangle(1*r,1*r,800*r,-1100*r);//Print Area Rect
if(pDC->IsPrinting())
{
DrawEditText(pDC);//Simple Edit box text
DrawRichText(pDC);//My RichEdit box text
}
/*E**********************************************/
}
#define IDC_REDIT 4001 //defining a resource ID
#define IDC_EDIT 4002 //defining a resource ID
void CRTCtrlPrint1View::RTCtrlCreate() //creates both Rich edit & Edit Controls
{
/*B**********************************************/
CRect m_temp;
CClientDC dc(this);
OnPrepareDC(&dc);
//creating edit box in scroll view
m_temp = m_edRect;
dc.LPtoDP(m_temp);
m_edit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_EDIT);
m_edit.SetFont(&font,FALSE);
m_edit.SetWindowText("Help Me! Thank u");
//creating rich edit box in scroll view
m_temp = m_redRect;
dc.LPtoDP(m_temp);
m_redit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_REDIT);
//writing some text in richtext control
CString str;
str="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\froman\\fprq2\\fcharset0 Times New Roman;}{\\f1\\fswiss\\fprq2\\fcharset0 System;}}{\\colortbl ;\\red255\\green0\\blue0;\\red51\\green153\\blue102;\\red0\\green0\\blue255;}\\viewkind4\\uc1\\pard\\cf1\\i\\f0\\fs24 ThankYou\
\\cf0\\i0 \\cf2\\b for\
\\cf0\\b0 \\cf3 Trying\
\\cf0 !\\b\\f1\\fs20 \\par }";
EDITSTREAM es;
es.dwCookie = (DWORD)&str;
es.pfnCallback = RichEditStreamInCallback;
m_redit.StreamIn(SF_RTF,es);
/*E**********************************************/
}
void CRTCtrlPrint1View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
/*B**********************************************/
// pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetMapMode(MM_TWIPS);
/*E**********************************************/
}
void CRTCtrlPrint1View::DrawEditText(CDC *pDC)
{
/*B**********************************************/
CRect m_temp;
m_temp = m_edRect;
CString str;
m_edit.GetWindowText(str);
pDC->SetBkMode(TRANSPARENT);
pDC->Rectangle(m_temp);
//Draws with Fonts as we wish
pDC->DrawText(str,m_temp,DT_WORDBREAK|DT_EXPANDTABS|DT_NOPREFIX);
/*E**********************************************/
}
//***************************************************************************************
// I want to draw the RichTextControl content in a specified rectangle on my printing page
// (as i done with editbox control) using FormatRange function with the different
// Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this function ?..
//***************************************************************************************
void CRTCtrlPrint1View::DrawRichText(CDC *pDC)
{
/*B**********************************************/
CRect m_temp;
FORMATRANGE fmtRange;
long lLineWidth;
m_temp = m_redRect;
// pDC->LPtoDP(m_temp);
pDC->Rectangle(m_temp);
lLineWidth = ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH), 1440, pDC->GetDeviceCaps(LOGPIXELSX));
fmtRange.hdc = pDC->m_hDC;
fmtRange.hdcTarget = pDC->m_hDC;
fmtRange.rc = m_temp;
fmtRange.rcPage = m_temp;
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
m_redit.SetTargetDevice(pDC->m_hDC, lLineWidth);
m_redit.FormatRange(&fmtRange, TRUE);
/*E**********************************************/
}
any body brave..
Balaji
|
|
|
|
|
Hi,
not really the right forum, but perhaps here is an RTF expert
I wanted to use the RTF/CRichEditCtrl as a kind of report system, where the reports are generated from templates of rtf files. A first simple solution would be to search and replace Tags within the RTF file with the computed values.
A better solution would be to use the field tag from the RTF specification directly. For example the author field from a word document would look like:
{\field{\*\fldinst
{ AUTHOR \\* MERGEFORMAT }}{\fldrslt {Dirk}}}
where fldinst is the specific field instruction and fldrslt is the latest evaluated result.
Unhappily the CRichEditCtrl does not evaluate internal fields (like author) either, and I couldn't find any Interface in the ITextDocument specification to access the fields of the document.
Does anybody know how to reevaluate the contents of fields programmatically? Something like a callback function with the fied instruction (fldinst) and the return value is the evaluated result? Another possibility would be to reparse the complete document again and aply the evaluated values into the result field (fldrslt) and then feed the document back to the Ctrl.
Any ideas / code?
Thanks
|
|
|
|
|
RTF documents can have informations that are not displayed like author information, version etc.
Has anyone tried to add and retrieve for example author information to a RTF document? Also has anyone tried to add bitmaps to a RTF document?
|
|
|
|
|
Can you tell us what was updated?
Thanks
|
|
|
|
|
I'm honestly not sure of that myself... My guess is that it was just some sort of administrative thing?
|
|
|
|
|
NT4/VS.NET needs replacement in this fct:
// for (int i = 0; i <= sFontName.GetLength()-1; i++)
// cf.szFaceName[i] = sFontName[i];
lstrcpy(cf.szFaceName,sFontName);
otherwise the szFaceName will keep letters in szFaceName that are not replaced, sometimes causing a crash!
|
|
|
|
|
Yes, I just stumbled across that, too ... I did a slightly different fix, by adding the following after the for loop:
cf.szFaceName[sFontName.GetLength()] = '\0';
|
|
|
|
|
SetFontName doesn't seem to function for me.
|
|
|
|
|
It should work just fine, as long as you supply a nul byte after the name of the font. My earlier posting showed how this was done, as did Anonymous' posting about the bug.
|
|
|
|
|
I am using richedit20.dll(version). Most of the features like multi undo and redo work but somehow the paste doesn't work. It cuts the text but doesn't paste it. If I cut the text from some other application and try paste, it works.When I look at the clipboard there is nothing in it. I am using CRichEditView. I tried GetPriorityClipboardFormat(), but it returns -1.
Thanks
|
|
|
|
|
To print directly from the control add the following method (from Al Williams website)
<br />
BOOL CAutoRichEditCtrl::Print(CString Title)<br />
{<br />
CDC ThePrintDC;
CPrintDialog PrintDialog(FALSE);
<br />
if(PrintDialog.DoModal()==IDOK)
{<br />
ThePrintDC.Attach(PrintDialog.GetPrinterDC());
}<br />
else<br />
return FALSE;
long CharRange=0;<br />
long LastChar=0;
DOCINFO di;
::ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize=sizeof(DOCINFO);
di.lpszDocName=Title;
FORMATRANGE fr;
::ZeroMemory(&fr, sizeof(FORMATRANGE));
HDC hdc=ThePrintDC.GetSafeHdc();
fr.hdc=hdc;
fr.hdcTarget=hdc;
int nHorizRes = ThePrintDC.GetDeviceCaps(HORZRES),
nVertRes = ThePrintDC.GetDeviceCaps(VERTRES),
nLogPixelsX = ThePrintDC.GetDeviceCaps(LOGPIXELSX),
nLogPixelsY = ThePrintDC.GetDeviceCaps(LOGPIXELSY);
fr.rcPage.left = 0;
fr.rcPage.top = 0;<br />
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440;
fr.rc.left = fr.rcPage.left + 1440;
fr.rc.top = fr.rcPage.top + 1440;<br />
fr.rc.right = fr.rcPage.right - 1440;<br />
fr.rc.bottom = fr.rcPage.bottom - 1440;<br />
CHARRANGE cr;<br />
cr.cpMin=0;<br />
cr.cpMax=-1;
fr.chrg=cr;
CharRange=GetTextLength();<br />
int ErrorStatus=0;<br />
<br />
ThePrintDC.StartDoc(&di);
do<br />
{<br />
ThePrintDC.StartPage();
LastChar = FormatRange( &fr, TRUE );
ErrorStatus=ThePrintDC.EndPage();
cr.cpMin=LastChar;
cr.cpMax=CharRange;
fr.chrg=cr;
}while(LastChar==0);
switch(ErrorStatus)<br />
{<br />
case SP_ERROR:<br />
{<br />
ThePrintDC.AbortDoc();<br />
AfxMessageBox("There was a general printing error, please check printer is working properly, connected, on line etc.", MB_OK | MB_ICONEXCLAMATION);<br />
return FALSE;<br />
}<br />
case SP_APPABORT:<br />
{<br />
ThePrintDC.AbortDoc();<br />
return FALSE;<br />
}<br />
case SP_USERABORT:<br />
{<br />
ThePrintDC.AbortDoc();<br />
return FALSE;<br />
}<br />
case SP_OUTOFDISK:<br />
{<br />
ThePrintDC.AbortDoc();<br />
AfxMessageBox("The print spooler is out of disk space, free up some disk space and try again.", MB_OK | MB_ICONEXCLAMATION);<br />
return FALSE;<br />
}<br />
case SP_OUTOFMEMORY:<br />
{<br />
ThePrintDC.AbortDoc();<br />
AfxMessageBox("Your computer is out of memory, shut down some applications and/or some windows and try again.", MB_OK | MB_ICONEXCLAMATION);<br />
return FALSE;<br />
}<br />
default:<br />
{<br />
ThePrintDC.EndDoc();<br />
return TRUE;<br />
}<br />
}<br />
<br />
}<br />
|
|
|
|
|
//***************************************************************************************
// I want to draw the RichTextControl content in a specified rectangle on my printing page
// (as i done with editbox control) using FormatRange function with the different
// Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this function ?..
//***************************************************************************************
//The partial code
//RTCtrlPrint1View.h
public:
CRTCtrlPrint1Doc* GetDocument();
//My*************************************
void RTCtrlCreate();
void DrawRichText(CDC *pDC);
void DrawEditText(CDC *pDC);
CRichEditCtrl m_redit;
CRect m_redRect;
CEdit m_edit;
CRect m_edRect;
UINT r;
CFont font;
//**************************************
//RTCtrlPrint1View.cpp
void CRTCtrlPrint1View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
/*B**********************************************/
//edith box displaytext font
font.CreateFont(14,0,0,0,FW_NORMAL,FALSE,FALSE,
0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_MODERN,"Arial");
r=14;
m_edRect = CRect(50*r,-100*r,240*r,-700*r);
m_redRect = CRect(250*r,-100*r,750*r,-700*r);
CSize sizeTotal;
sizeTotal.cx = 850*r;
sizeTotal.cy = 1100*r;
SetScrollSizes(MM_TWIPS, sizeTotal); //MM_TWIPS
RTCtrlCreate();
/*E**********************************************/
}
void CRTCtrlPrint1View::OnDraw(CDC* pDC)
{
CRTCtrlPrint1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/*B**********************************************/
pDC->Rectangle(1*r,1*r,800*r,-1100*r);//Print Area Rect
if(pDC->IsPrinting())
{
DrawEditText(pDC);//Simple Edit box text
DrawRichText(pDC);//My RichEdit box text
}
/*E**********************************************/
}
#define IDC_REDIT 4001 //defining a resource ID
#define IDC_EDIT 4002 //defining a resource ID
void CRTCtrlPrint1View::RTCtrlCreate() //creates both Rich edit & Edit Controls
{
/*B**********************************************/
CRect m_temp;
CClientDC dc(this);
OnPrepareDC(&dc);
//creating edit box in scroll view
m_temp = m_edRect;
dc.LPtoDP(m_temp);
m_edit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_EDIT);
m_edit.SetFont(&font,FALSE);
m_edit.SetWindowText("Help Me! Thank u");
//creating rich edit box in scroll view
m_temp = m_redRect;
dc.LPtoDP(m_temp);
m_redit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_REDIT);
//writing some text in richtext control
CString str;
str="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\froman\\fprq2\\fcharset0 Times New Roman;}{\\f1\\fswiss\\fprq2\\fcharset0 System;}}{\\colortbl ;\\red255\\green0\\blue0;\\red51\\green153\\blue102;\\red0\\green0\\blue255;}\\viewkind4\\uc1\\pard\\cf1\\i\\f0\\fs24 ThankYou\
\\cf0\\i0 \\cf2\\b for\
\\cf0\\b0 \\cf3 Trying\
\\cf0 !\\b\\f1\\fs20 \\par }";
EDITSTREAM es;
es.dwCookie = (DWORD)&str;
es.pfnCallback = RichEditStreamInCallback;
m_redit.StreamIn(SF_RTF,es);
/*E**********************************************/
}
void CRTCtrlPrint1View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
/*B**********************************************/
// pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetMapMode(MM_TWIPS);
/*E**********************************************/
}
void CRTCtrlPrint1View::DrawEditText(CDC *pDC)
{
/*B**********************************************/
CRect m_temp;
m_temp = m_edRect;
CString str;
m_edit.GetWindowText(str);
pDC->SetBkMode(TRANSPARENT);
pDC->Rectangle(m_temp);
//Draws with Fonts as we wish
pDC->DrawText(str,m_temp,DT_WORDBREAK|DT_EXPANDTABS|DT_NOPREFIX);
/*E**********************************************/
}
//***************************************************************************************
// I want to draw the RichTextControl content in a specified rectangle on my printing page
// (as i done with editbox control) using FormatRange function with the different
// Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this function ?..
//***************************************************************************************
void CRTCtrlPrint1View::DrawRichText(CDC *pDC)
{
/*B**********************************************/
CRect m_temp;
FORMATRANGE fmtRange;
long lLineWidth;
m_temp = m_redRect;
// pDC->LPtoDP(m_temp);
pDC->Rectangle(m_temp);
lLineWidth = ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH), 1440, pDC->GetDeviceCaps(LOGPIXELSX));
fmtRange.hdc = pDC->m_hDC;
fmtRange.hdcTarget = pDC->m_hDC;
fmtRange.rc = m_temp;
fmtRange.rcPage = m_temp;
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
m_redit.SetTargetDevice(pDC->m_hDC, lLineWidth);
m_redit.FormatRange(&fmtRange, TRUE);
/*E**********************************************/
}
any body brave..
Balaji
|
|
|
|
|
I Try to used this AutoRichEdit. That work very well on win 9X & Win XP. But there is probleme on Win NT. Moreover, the "demo" doesn't work on NT.
Have you got an idea to solve my problem
|
|
|
|
|
I can affirm this.. the font is not changed, no matter what functions you choose in the demo. A fix would be very nice.
|
|
|
|
|
What changes are needed in order to get this control to move the cursor when the tab key is pressed. Similar to MS Word when the key is pressed..
Samir
|
|
|
|
|
hello samir
if u have a prefect control over how u display ur text .implementing tabs is very simple
first u must know the x-coordinate of ur cursor.
the default tab is 5 times the width of space character for that particular font .
tap the key board for tab press and move ur cursor to the width ur require .
|
|
|
|
|
How to format the spacing in RichEdit2.0. CHARFORMAT2 is a rich edit 2.0 extension of the CHARFORMAT structure,But I can't control the menber sSpacing to format my word. Who can help me ?
|
|
|
|
|
... but it doesn't support Unicode at all.
Would be nice to have this...
Best regards,
Vladimir
|
|
|
|
|
Hi :
I don't know how to use RichEditCtrl in a dialog box?
(of course, I don't how to use AfxInitRichEdit function in Initinstance?)
|
|
|
|
|
When you use the ClassWizard to create a Dialogbox, you end up with 2 classes(not counting the About box dialog class). The class w/ the "App" postfix is where you'll find the Initinstance method.
For instance, if you create a Dialog project named "Dialog" then you end up w/ the following classes.
-CDialogDlg
-CDialogApp
-CAboutDlg
In this case you should include the "AfxInitRichEdit();" in the CDialogApp::Initinstance().
BOOL COFFICE10SerialApp::InitInstance()
{
AfxEnableControlContainer();
AfxInitRichEdit(); //Add this line
...
return FALSE;
}
Now just add a RichEdit Control to your Dialog like you would with any other controls. If you need more info then go visit the MSDN Online site and do some search for Rich Edit Control.
|
|
|
|
|
If I put AutoHScroll as an attribute for your Rich Edit Control the alignment of paragraphs does not work anymore.Why? Maybe because it is not known how long it is the line?
Frunza Adriana
|
|
|
|
|
Good Code, Congratulation.
In my application this function doesn't work because cf.szFacename need a finish. I Add line cf.szFaceName[i]='\0', and Now work very well.
void CAutoRichEditCtrl::SetFontName(CString sFontName)
{
CHARFORMAT cf = GetCharFormat();
// Set the font name.
for (int i = 0; i <= sFontName.GetLength()-1; i++)
cf.szFaceName[i] = sFontName[i];
cf.szFaceName[i]='\0'; // Add this line please..
cf.dwMask = CFM_FACE;
SetSelectionCharFormat(cf);
}
|
|
|
|
|
error!!
for (int i = 0; i <= sFontName.GetLength()-1; i++)
cf.szFaceName[i] = sFontName[i];
chang:
_tcscpy(cf.szFaceName, sFontName);
|
|
|
|
|
I have problem in handling functions like FormatRange followed by DisplayBand in CRichEditCtrl. I tried to print the contents directly from the control created in a scrollview. Actually the problem lies in setting the mapping mode. I hope you can able to give a better solution for this problem.
|
|
|
|
|
Great control.
Is there any way of retreiving just the raw text from the control (w/o the RTF formating) or is there a conversion routine to convert between RTF and normal text?
Johannes
|
|
|
|
|