Problem with Set Text Format in RichEditView class 
Author Message
 Problem with Set Text Format in RichEditView class

Hi all,

I've created an MDI Application with RichEditView. Then, in side the
MyRichEditView.cpp file, i changed the setting for the text including color
and character formatting attributes for a current word.
This is working fine if i compile the program under Debug version.
However, It does not work if i compile the program under Release version,
the text displayed as default setting though i did change its setting.

Does anyone know why?

Any idea, comment or suggestion would be appriciated.

Thanks in advance.

-BP



Sat, 05 Mar 2005 15:58:40 GMT  
 Problem with Set Text Format in RichEditView class
Hi Bachlan,

Check if you call ZeroMemory to initialize the CHARFORMAT structure. In
debug build, the memory is initialized. If some members of the structures
are not set properly, the problem won't appear in debug build.

Please check the article below for a sample of setting the character format:

http://msdn.microsoft.com/library/en-us/vcmfc98/html/_mfc_cricheditct...
setselectioncharformat.asp

Note: The URL may wrap.

I hope it helps.

Best Regards,
Leo Chen

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

| Subject: Problem with Set Text Format in RichEditView class
| Date: Tue, 17 Sep 2002 10:58:40 -0400
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

| Newsgroups: microsoft.public.vc.mfc
| NNTP-Posting-Host: 205.68.95.65
| Path: cpmsftngxa07!tkmsftngp01!tkmsftngp09
| Xref: cpmsftngxa07 microsoft.public.vc.mfc:3322
| X-Tomcat-NG: microsoft.public.vc.mfc
|
| Hi all,
|
| I've created an MDI Application with RichEditView. Then, in side the
| MyRichEditView.cpp file, i changed the setting for the text including
color
| and character formatting attributes for a current word.
| This is working fine if i compile the program under Debug version.
| However, It does not work if i compile the program under Release version,
| the text displayed as default setting though i did change its setting.
|
| Does anyone know why?
|
| Any idea, comment or suggestion would be appriciated.
|
| Thanks in advance.
|
| -BP
|
|
|



Mon, 07 Mar 2005 06:52:47 GMT  
 Problem with Set Text Format in RichEditView class
No, I does not work though I called ZeroMemory() before
SetSelectionCharFormat();
Here is what i did:
class CAnalysisView : public CRichEditView
{
    CHARFORMAT fmt_green;

Quote:
}

CAnalysisView::CAnalysisView()
{
  // "Green" text
    ZeroMemory( &fmt_green, sizeof(fmt_green));
    fmt_green.dwEffects = 0; // DWORD ... character effects
    fmt_green.crTextColor = RGB(0,200,75); // COLORREF ... text color
0,200,75
    fmt_green.cbSize = sizeof(fmt_green); // UINT ... size of this structure
Quote:
}

void CAnalysisView::OnInitialUpdate()
{
     CRichEditCtrl &thisEdit = GetRichEditCtrl();
      addText(thisEdit , _T("This is a Green Text \n"), fmt_green);

Quote:
}

void CAnalysisView::addText(CRichEditCtrl &myEdit, LPCTSTR  newText,
CHARFORMAT textFormat)
{
     int nBegin, nEnd;
     nBegin = getCurrentPosition(myEdit);
     myEdit.ReplaceSel(newText);
     nEnd = getCurrentPosition(myEdit);
     myEdit.SetSel(nBegin, nEnd);

     ZeroMemory( &textFormat, sizeof(textFormat));
     myEdit.SetSelectionCharFormat(textFormat) ;
     myEdit.SetSel(nEnd,nEnd);

Quote:
}

int CAnalysisView::getCurrentPosition(CRichEditCtrl &myEdit)
{
     return myEdit.LineIndex(-1) + myEdit.LineLength(-1);

Quote:
}

-BP

~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Quote:
> Hi Bachlan,

> Check if you call ZeroMemory to initialize the CHARFORMAT structure. In
> debug build, the memory is initialized. If some members of the structures
> are not set properly, the problem won't appear in debug build.

> Please check the article below for a sample of setting the character
format:

http://msdn.microsoft.com/library/en-us/vcmfc98/html/_mfc_cricheditct...
Quote:
> setselectioncharformat.asp

> Note: The URL may wrap.

> I hope it helps.

> Best Regards,
> Leo Chen

> This posting is provided "AS IS" with no warranties, and confers no
rights.

> --------------------

> | Subject: Problem with Set Text Format in RichEditView class
> | Date: Tue, 17 Sep 2002 10:58:40 -0400
> | Lines: 18
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
> | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

> | Newsgroups: microsoft.public.vc.mfc
> | NNTP-Posting-Host: 205.68.95.65
> | Path: cpmsftngxa07!tkmsftngp01!tkmsftngp09
> | Xref: cpmsftngxa07 microsoft.public.vc.mfc:3322
> | X-Tomcat-NG: microsoft.public.vc.mfc
> |
> | Hi all,
> |
> | I've created an MDI Application with RichEditView. Then, in side the
> | MyRichEditView.cpp file, i changed the setting for the text including
> color
> | and character formatting attributes for a current word.
> | This is working fine if i compile the program under Debug version.
> | However, It does not work if i compile the program under Release
version,
> | the text displayed as default setting though i did change its setting.
> |
> | Does anyone know why?
> |
> | Any idea, comment or suggestion would be appriciated.
> |
> | Thanks in advance.
> |
> | -BP
> |
> |
> |



Mon, 07 Mar 2005 14:15:03 GMT  
 Problem with Set Text Format in RichEditView class
Hi Bachlan,

The code has some issues. Variable textFormat (i.e.fmt_green) is
initialized in CAnalysisView's constructor. However, it is set to zero
before calling myEdit.SetSelectionCharFormat(textFormat). Thus, it doesn't
have the expected behavior. You may want to remove the ZeroMemory line just
before myEdit.SetSelectionCharFormat(textFormat).

In addition, fmt_green.dwMask is not set. Please add the following line in
CAnalysisView::CAnalysisView

fmt_green.dwMask = CFM_COLOR;

Best Regards,
Leo Chen

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------


| Subject: Re: Problem with Set Text Format in RichEditView class
| Date: Thu, 19 Sep 2002 09:15:03 -0400
| Lines: 110
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

| Newsgroups: microsoft.public.vc.mfc
| NNTP-Posting-Host: 205.68.95.65
| Path: cpmsftngxa07!cpmsftngxa09!cpmsftngxa08!tkmsftngp01!tkmsftngp08
| Xref: cpmsftngxa07 microsoft.public.vc.mfc:3714
| X-Tomcat-NG: microsoft.public.vc.mfc
|
| No, I does not work though I called ZeroMemory() before
| SetSelectionCharFormat();
| Here is what i did:
| class CAnalysisView : public CRichEditView
| {
|     CHARFORMAT fmt_green;
| }
|
| CAnalysisView::CAnalysisView()
| {
|   // "Green" text
|     ZeroMemory( &fmt_green, sizeof(fmt_green));
|     fmt_green.dwEffects = 0; // DWORD ... character effects
|     fmt_green.crTextColor = RGB(0,200,75); // COLORREF ... text color
| 0,200,75
|     fmt_green.cbSize = sizeof(fmt_green); // UINT ... size of this
structure
| }
| void CAnalysisView::OnInitialUpdate()
| {
|      CRichEditCtrl &thisEdit = GetRichEditCtrl();
|       addText(thisEdit , _T("This is a Green Text \n"), fmt_green);
| }
|
| void CAnalysisView::addText(CRichEditCtrl &myEdit, LPCTSTR  newText,
| CHARFORMAT textFormat)
| {
|      int nBegin, nEnd;
|      nBegin = getCurrentPosition(myEdit);
|      myEdit.ReplaceSel(newText);
|      nEnd = getCurrentPosition(myEdit);
|      myEdit.SetSel(nBegin, nEnd);
|
|      ZeroMemory( &textFormat, sizeof(textFormat));
|      myEdit.SetSelectionCharFormat(textFormat) ;
|      myEdit.SetSel(nEnd,nEnd);
| }
| int CAnalysisView::getCurrentPosition(CRichEditCtrl &myEdit)
| {
|      return myEdit.LineIndex(-1) + myEdit.LineLength(-1);
| }
|
| -BP
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


| > Hi Bachlan,
| >
| > Check if you call ZeroMemory to initialize the CHARFORMAT structure. In
| > debug build, the memory is initialized. If some members of the
structures
| > are not set properly, the problem won't appear in debug build.
| >
| > Please check the article below for a sample of setting the character
| format:
| >
| >
|
http://msdn.microsoft.com/library/en-us/vcmfc98/html/_mfc_cricheditct...
| > setselectioncharformat.asp
| >
| > Note: The URL may wrap.
| >
| > I hope it helps.
| >
| > Best Regards,
| > Leo Chen
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| >
| > --------------------

| > | Subject: Problem with Set Text Format in RichEditView class
| > | Date: Tue, 17 Sep 2002 10:58:40 -0400
| > | Lines: 18
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
| > | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

| > | Newsgroups: microsoft.public.vc.mfc
| > | NNTP-Posting-Host: 205.68.95.65
| > | Path: cpmsftngxa07!tkmsftngp01!tkmsftngp09
| > | Xref: cpmsftngxa07 microsoft.public.vc.mfc:3322
| > | X-Tomcat-NG: microsoft.public.vc.mfc
| > |
| > | Hi all,
| > |
| > | I've created an MDI Application with RichEditView. Then, in side the
| > | MyRichEditView.cpp file, i changed the setting for the text including
| > color
| > | and character formatting attributes for a current word.
| > | This is working fine if i compile the program under Debug version.
| > | However, It does not work if i compile the program under Release
| version,
| > | the text displayed as default setting though i did change its setting.
| > |
| > | Does anyone know why?
| > |
| > | Any idea, comment or suggestion would be appriciated.
| > |
| > | Thanks in advance.
| > |
| > | -BP
| > |
| > |
| > |
| >
|
|
|



Tue, 08 Mar 2005 07:48:39 GMT  
 Problem with Set Text Format in RichEditView class
Hi Leo,

Yes...It works now...Thank you very much for your responses.

-BP,

~~~~~~~~~~~~~~~~~~~~~~~~~~~


Quote:
> Hi Bachlan,

> The code has some issues. Variable textFormat (i.e.fmt_green) is
> initialized in CAnalysisView's constructor. However, it is set to zero
> before calling myEdit.SetSelectionCharFormat(textFormat). Thus, it doesn't
> have the expected behavior. You may want to remove the ZeroMemory line
just
> before myEdit.SetSelectionCharFormat(textFormat).

> In addition, fmt_green.dwMask is not set. Please add the following line in
> CAnalysisView::CAnalysisView

> fmt_green.dwMask = CFM_COLOR;

> Best Regards,
> Leo Chen

> This posting is provided "AS IS" with no warranties, and confers no
rights.

> --------------------




- Show quoted text -

Quote:
> | Subject: Re: Problem with Set Text Format in RichEditView class
> | Date: Thu, 19 Sep 2002 09:15:03 -0400
> | Lines: 110
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
> | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

> | Newsgroups: microsoft.public.vc.mfc
> | NNTP-Posting-Host: 205.68.95.65
> | Path: cpmsftngxa07!cpmsftngxa09!cpmsftngxa08!tkmsftngp01!tkmsftngp08
> | Xref: cpmsftngxa07 microsoft.public.vc.mfc:3714
> | X-Tomcat-NG: microsoft.public.vc.mfc
> |
> | No, I does not work though I called ZeroMemory() before
> | SetSelectionCharFormat();
> | Here is what i did:
> | class CAnalysisView : public CRichEditView
> | {
> |     CHARFORMAT fmt_green;
> | }
> |
> | CAnalysisView::CAnalysisView()
> | {
> |   // "Green" text
> |     ZeroMemory( &fmt_green, sizeof(fmt_green));
> |     fmt_green.dwEffects = 0; // DWORD ... character effects
> |     fmt_green.crTextColor = RGB(0,200,75); // COLORREF ... text color
> | 0,200,75
> |     fmt_green.cbSize = sizeof(fmt_green); // UINT ... size of this
> structure
> | }
> | void CAnalysisView::OnInitialUpdate()
> | {
> |      CRichEditCtrl &thisEdit = GetRichEditCtrl();
> |       addText(thisEdit , _T("This is a Green Text \n"), fmt_green);
> | }
> |
> | void CAnalysisView::addText(CRichEditCtrl &myEdit, LPCTSTR  newText,
> | CHARFORMAT textFormat)
> | {
> |      int nBegin, nEnd;
> |      nBegin = getCurrentPosition(myEdit);
> |      myEdit.ReplaceSel(newText);
> |      nEnd = getCurrentPosition(myEdit);
> |      myEdit.SetSel(nBegin, nEnd);
> |
> |      ZeroMemory( &textFormat, sizeof(textFormat));
> |      myEdit.SetSelectionCharFormat(textFormat) ;
> |      myEdit.SetSel(nEnd,nEnd);
> | }
> | int CAnalysisView::getCurrentPosition(CRichEditCtrl &myEdit)
> | {
> |      return myEdit.LineIndex(-1) + myEdit.LineLength(-1);
> | }
> |
> | -BP
> |
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


> | > Hi Bachlan,
> | >
> | > Check if you call ZeroMemory to initialize the CHARFORMAT structure.
In
> | > debug build, the memory is initialized. If some members of the
> structures
> | > are not set properly, the problem won't appear in debug build.
> | >
> | > Please check the article below for a sample of setting the character
> | format:
> | >
> | >
> |

http://msdn.microsoft.com/library/en-us/vcmfc98/html/_mfc_cricheditct...

- Show quoted text -

Quote:
> | > setselectioncharformat.asp
> | >
> | > Note: The URL may wrap.
> | >
> | > I hope it helps.
> | >
> | > Best Regards,
> | > Leo Chen
> | >
> | > This posting is provided "AS IS" with no warranties, and confers no
> | rights.
> | >
> | >
> | > --------------------

> | > | Subject: Problem with Set Text Format in RichEditView class
> | > | Date: Tue, 17 Sep 2002 10:58:40 -0400
> | > | Lines: 18
> | > | X-Priority: 3
> | > | X-MSMail-Priority: Normal
> | > | X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
> | > | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

> | > | Newsgroups: microsoft.public.vc.mfc
> | > | NNTP-Posting-Host: 205.68.95.65
> | > | Path: cpmsftngxa07!tkmsftngp01!tkmsftngp09
> | > | Xref: cpmsftngxa07 microsoft.public.vc.mfc:3322
> | > | X-Tomcat-NG: microsoft.public.vc.mfc
> | > |
> | > | Hi all,
> | > |
> | > | I've created an MDI Application with RichEditView. Then, in side the
> | > | MyRichEditView.cpp file, i changed the setting for the text
including
> | > color
> | > | and character formatting attributes for a current word.
> | > | This is working fine if i compile the program under Debug version.
> | > | However, It does not work if i compile the program under Release
> | version,
> | > | the text displayed as default setting though i did change its
setting.
> | > |
> | > | Does anyone know why?
> | > |
> | > | Any idea, comment or suggestion would be appriciated.
> | > |
> | > | Thanks in advance.
> | > |
> | > | -BP
> | > |
> | > |
> | > |
> | >
> |
> |
> |



Tue, 08 Mar 2005 13:26:17 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. RichEditView text formatting

2. RichEditView text formatting

3. Setting the text color in a CEditVioew derived class

4. Setting property Text in a class derived from UpDownBase

5. Programatically insert text into RichEditView?

6. Hide text in RichEditView

7. How to print text in RichEditView?

8. Inserting Text Boxes in a RichEditView

9. Is it possible to capture the visible richeditview text

10. Scrolling text, pixel by pixel in a RichEditView

11. Inserting Text Boxes in a RichEditView

12. How to save a file in Microsoft word format(.doc) or Rich text format

 

 
Powered by phpBB® Forum Software