Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EM_SETCHARFORMATand SCF_SELECTION blocks rich editor behavio
#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);


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)