|
|
Comments and Discussions
|
|
 |

|
Hi
I am a desperate person trying to finish off a program started many years back before i retire; but have struggled with trying to set default parameters using CAutoRichEditin in an edit box in an mfc dialog project this is one control on a dialog with several other edit boxes that are just ordinary edit boxes.
Have set default text for box using : ac[0].REFormular = "{\\rtf1 CH3.COOH \\par }"; , this is part of a structure. Have tried several different ways setting default but never can save to structure or to file.
|
|
|
|

|
Have problem where by need to set the font and size to fit an edit box in a dialog form that uses other normal edit boxes; my problem is that unable to save anything modified or added to a richedit box, the CString that is used to store the rich text is part of a structure eg:
struct AmountSol{
int subID;
char Substance[70];
char Altname[70];
char Formula[50];
char Solubility[12];
char Wttype[6];
char Pristd[12];
double Density;
double Purity;
double Normal;
double Molar;
double MolWt;
CString sText; // stores rich edit text
};
AmountSol ac[Smax];
My thinking is that the box needs to be set with defaults but cannot work out how?
Can someone please help
Many thanks
Candleman
|
|
|
|

|
Worked perfectly right out of the gate.
|
|
|
|

|
Jeremy,
GetRTF() was just what I've been looking for.
Now all I need is ConvertRTFtoHTML()
--jay
|
|
|
|

|
If the support GIF / BMP ....
|
|
|
|
|

|
I have a DLL that I am trying to use this control in, and the DLL has to be UNICODE. I am trying to auto populate the control with text when the user does something in the dialog. I am using the control only for formatted information display, no edit ability when it ships to the user, but is editable during my debugging. When I call SetRTF, nothing appears in the control. If I manually type something in it and then do something in the dialog that causes it to change, the text I typed in will disappear, but no new text appears. In order to get it to compile in UNICODE I had to change the following line in the streamin function.
memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
to
memcpy(pbBuff, (LPCTSTR) *pstr, *pcb * sizeof(TCHAR));
Since I am in a DLL, I could not call AfxInitRichEdit in the InitInstance, so I placed it in the DllMain function instead.
Any ideas on how to get it to work?
I am using Visual Studio 2005
I converted the demo app to UNICODE and it exhibits the same behaviour. I can type text in the RichEditCtrl and execute the GetRTF command and it shows the formatted text in the top edit box, and can immediately execute the SetRTF command and the RichEditCtrl empties.
-- modified at 12:48 Monday 12th February, 2007
|
|
|
|

|
can this class support tables and tab stops, font colouring etc etc etc?
Andrew
|
|
|
|

|
Necessary to generate a DLL that to recoup the text formatted (rtf) for a CString. How I must proceed?
|
|
|
|

|
1.Riched20.dll different.
2.Unicode and DBCS
replace dll, but problem stay?
Can you help me?
|
|
|
|
|

|
Hi,
What is the correct way to capture Tab Key presses in a RichEditCtrl. I saw the answer for Catching tabs but was not convinced with the answer. If I have to get the current position of the Cursor in the RichEditCtrl (GetSel()), how do I do that, and from there on how do I insert a Tab.
Some one could help me.
Thanks and Regards
Frank
|
|
|
|

|
I have tried using the CAutoRichEditCtrl class (which is great) but i have stumbled upon a problem. I enable the control to recieve OLE objects (in my case pictures) by implementing IRichEditOleCallback and adding a SetOLECallback to my InitDialog. This works fine, the control accepts bitmap objects and the GetRTF function returns perfect RTF code containing all the OLE items.
The problem is that when i try to insert this text back into the control all OLE objects are removed and replaced by spaces. When i insert the same text into a CRichEditView all is fine.
Any ideas how this can be corrected?
|
|
|
|

|
iam using a different font in which some characters have a dot above it. whenever i try to write such characters a white space gets automatically appended. how do i remove such white spaces???
please help me......
thanks!
ramya.
|
|
|
|

|
ok - i can retrieve text from the control
but how do i insert text to it ? (not using GUI ofcourse)
(btw - Great Control)
|
|
|
|
|

|
I think it's not releated to your code - but an error in RichEdit control itself. Try this:
Add a bullet and write something, then add few blank lines and write something. It should looks like that:
* some text
another text
Then click on GetRTF and SetRTF few times - extrad dots are beign generated!
Any idea how to get rid of this ?
Thanks!
Irek
Check out my software at: http://www.ireksoftware.com
|
|
|
|

|
//***************************************************************************************
// 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
|
|
|
|

|
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!
|
|
|
|

|
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)
BOOL CAutoRichEditCtrl::Print(CString Title)
{
CDC ThePrintDC; //create a device context to use
CPrintDialog PrintDialog(FALSE); //make a print dialog too
if(PrintDialog.DoModal()==IDOK) //pressed the ok button on the print dialog?
{
ThePrintDC.Attach(PrintDialog.GetPrinterDC());//if so get settings
}
else
return FALSE; //leave this procedure, before anything bad happens
long CharRange=0;
long LastChar=0;//will store document length
DOCINFO di; //make a docinfo structure
::ZeroMemory(&di, sizeof(DOCINFO)); //need to be claer, so clear stuff from it
di.cbSize=sizeof(DOCINFO); //set size member
di.lpszDocName=Title;//set doc name, was passed via another funtion
FORMATRANGE fr; //make a format range structure
::ZeroMemory(&fr, sizeof(FORMATRANGE));//clear stuff from it
HDC hdc=ThePrintDC.GetSafeHdc(); //get handle to DC we are using
fr.hdc=hdc; //Set meber in FormatRange struct
fr.hdcTarget=hdc; //Set member in FormatRange struct
//This bit here will get all the dimentions of the printer setup
int nHorizRes = ThePrintDC.GetDeviceCaps(HORZRES), //width P in MM
nVertRes = ThePrintDC.GetDeviceCaps(VERTRES), //hight in raster lines
nLogPixelsX = ThePrintDC.GetDeviceCaps(LOGPIXELSX), //pixels per inch along x
nLogPixelsY = ThePrintDC.GetDeviceCaps(LOGPIXELSY); //pixels per inch along y
//set the printable area of printer in the FormatRange struct
fr.rcPage.left = 0; //these 2 mean top left
fr.rcPage.top = 0;
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;//these 2 mean bottom right
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440; //equation changes pixel to TWIPS
// Set up some margins all around. Make them one inch
//results vary on printers depending on setup
fr.rc.left = fr.rcPage.left + 1440; // 1440 TWIPS = 1 inch.
fr.rc.top = fr.rcPage.top + 1440;
fr.rc.right = fr.rcPage.right - 1440;
fr.rc.bottom = fr.rcPage.bottom - 1440;
//select all text for printing
CHARRANGE cr;
cr.cpMin=0;
cr.cpMax=-1;//-1 selects all
fr.chrg=cr;//set this in FormatRange struct
//get length of document, used for more than one page
CharRange=GetTextLength();
int ErrorStatus=0;
//Start Printing
//ThePrintDC.SetAbortProc(&AbortProc(hdc, )); //dont know how callbacks works yet
ThePrintDC.StartDoc(&di); //start printing document
do
{
ThePrintDC.StartPage(); //start the page
LastChar = FormatRange( &fr, TRUE );//send text to DC, and record index
//of last fitting char
ErrorStatus=ThePrintDC.EndPage();//end this page, and record status
cr.cpMin=LastChar;//Change charrange struct for next page
cr.cpMax=CharRange; //using last char printed
fr.chrg=cr; //set that in formatrange struct
}while(LastChar==0); //while there is stuff to print ot there
//is not an error(error is -No)
//if there is an error or printing has finished
//have to make sure AbortDoc is called instead of EndDoc if there has been a problem
switch(ErrorStatus)
{
case SP_ERROR:
{
ThePrintDC.AbortDoc();
AfxMessageBox("There was a general printing error, please check printer is working properly, connected, on line etc.", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
case SP_APPABORT:
{
ThePrintDC.AbortDoc();
return FALSE;
}
case SP_USERABORT:
{
ThePrintDC.AbortDoc();
return FALSE;
}
case SP_OUTOFDISK:
{
ThePrintDC.AbortDoc();
AfxMessageBox("The print spooler is out of disk space, free up some disk space and try again.", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
case SP_OUTOFMEMORY:
{
ThePrintDC.AbortDoc();
AfxMessageBox("Your computer is out of memory, shut down some applications and/or some windows and try again.", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
default:
{
ThePrintDC.EndDoc();
return TRUE;
}
}
}
|
|
|
|

|
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
|
|
|
|

|
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
|
|
|
|

|
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?)
|
|
|
|

|
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);
}
|
|
|
|

|
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
|
|
|
|

|
By looking at MFC42
BOOL PASCAL AfxInitRichEdit()
{
_AFX_RICHEDIT_STATE* pState = _afxRichEditState;
if (pState->m_hInstRichEdit == NULL)
pState->m_hInstRichEdit = LoadLibraryA("RICHED32.DLL");
return pState->m_hInstRichEdit != NULL;
}
In order to load the RichEdit Control 3.0, is it correct do following thing?
#include "afximpl.h"
BOOL CRich2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
_AFX_RICHEDIT_STATE* pState = _afxRichEditState;
if (pState->m_hInstRichEdit == NULL)
pState->m_hInstRichEdit = LoadLibraryA("RICHED20.DLL");
so we are not using the PreCreateWindow provided by the default CRichEditView ..., and loading the new DLL.
If that is the case, how come there is an error message about failing creating empty document after i did that. Are there more things i need to change?
Thanks.
|
|
|
|

|
Does anyone care to take a crack at making a WTL version of this? Probably want to avoid the WTL CString, as it is limited to 1k (and adds CRT dependency)
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A CRichEditCtrl derived class to handle formatting quickly.
| Type | Article |
| Licence | CPOL |
| First Posted | 19 Nov 1999 |
| Views | 221,962 |
| Bookmarked | 81 times |
|
|