Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EM_SETCHARFORMATand SCF_SELECTION blocks rich editor behavio
#1
I have small code for highlighting the text.

m_ctlEdit.SendMessage(EM_EXSETSEL,0,(LPARAM)&cr);
CHARFORMAT2 cf;
memset(&cf,0,sizeof(cf));
cf.cbSize=sizeof(cf);
cf.dwMask=CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_FACE|CFM_BACKCOLOR;
cf.crBackColor=GetSysColor(COLOR_WINDOW);
cf.crTextColor=GetSysColor(COLOR_WINDOWTEXT);
_tcscpy(cf.szFaceName,_T("Courier New"));
m_ctlEdit.SendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf);

But when i do this Undo/Redo operation is not working i.e ctrl Z. Instead of SCF_SELECTION if i use SCF_WORD it works fine. Where does the problem exist? Is it with SCF_SELECTION or my code?
#2
Rich edit control notifies parent about a format change as if it would be text change. Set event mask to 0, then restore.

Code:
Copy      Help
int mask=SendMessage(m_ctlEdit,EM_GETEVENTMASK,0,0);
SendMessage(m_ctlEdit,EM_SETEVENTMASK,0,0);

SendMessage(m_ctlEdit,EM_SETCHARFORMAT,SCF_SELECTION,&cf);

SendMessage(m_ctlEdit,EM_SETEVENTMASK,0,mask);

Also restore current selection (before restoring event mask), or undo may not work well in some cases.

This is some code from QM source:
Code:
Copy      Help
    Send(RE, EM_EXGETSEL, 0, &rsel);
    if(_n->visible && GetFocus()==RE) { focus=1; SetFocus(0); } //to prevent selection painting and autoscrolling
    Send(RE, EM_SETEVENTMASK, 0, 0);

    //removed code block that sets char format

    Send(RE, EM_EMPTYUNDOBUFFER, 0, 0);
    Send(RE, EM_EXSETSEL, 0, &rsel);
    if(focus && !f.nofocus) SetFocus(RE);
    Send(RE, EM_SETEVENTMASK, 0, mask);
#3
Thanks for your reply..

But setting EM_SETEVENTMASK also didn't succeed.

I read some articles where it has been stated that formatting the characters using EM_SETCHARFORMAT for a particular selection corrupts the UNDO buffer.

I guess the formatting steps are loaded into the UNDO buffer which corrupts the buffer.

Is there any way where i can stop loading the UNDO buffer while formatting and than again start loading the buffer after formatting?
#4
It works well with QM editor, which is based on version 1 of rich edit control. QM does not use rich edit control's undo feature.

Don't remember but rich edit control (maybe version 2 or 3) should have a message that turns off undo buffer, but it probably does not allow to turn off using undo for formatting.


Forum Jump:


Users browsing this thread: 2 Guest(s)