Link to home
Start Free TrialLog in
Avatar of roger_pearse
roger_pearse

asked on

CRichEditCtrl and switching between left-to-right and right-to-left text

I'm working on an SDI application which has a main window full of right-to-left text (in Syriac).  The window is a CRichEditCtrl in a CView.  Now I can set this fine like this:

   BOOL CmywinView::PreCreateWindow(CREATESTRUCT& cs)
   {
      // TODO: Modify the Window class or styles here by modifying
      //  the CREATESTRUCT cs

      cs.dwExStyle |= WS_EX_RTLREADING;

      return CRichEditView::PreCreateWindow(cs);
   }

and this all works.

But... it would be nice to be able to switch the text in this window between RightToLeft and LeftToRight from a menu option (people tend to enter text the wrong way sometimes).  

So I removed the above line from my PreCreateWindow and tried the following in order to get it to display in RTL:

   {
      CRichEditCtrl& rCtrl = GetRichEditCtrl();
      BOOL x = rCtrl.ModifyStyleEx(0, WS_EX_RTLREADING);
      if (x == TRUE) {
            TRACE0("TRUE");
      } else
            TRACE0("FALSE");
      {
      }
      rCtrl.SetWindowText(_T("hello"));
  }

This does not work .  TRUE is output -- but the text is determinedly left-to-right in the window.  Can anyone help?

All the best,

Roger Pearse

Avatar of mahesh1402
mahesh1402
Flag of India image

try like this :

rCtrl.ModifyStyleEx( WS_EX_LTRREADING, WS_EX_RTLREADING );


MAHESH
Avatar of roger_pearse
roger_pearse

ASKER

Thanks, but this doesn't work either.
Use the EM_SETPARAFORMAT message.  Set PFE_RTLPARA in the PARAFORMAT2 structure when sending
EM_SETPARAFORMAT message.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/paraformat2.asp

MAHESH

That sets the paragraph format, and might work -- I have not checked.  But it should clearly be possible to tweak the window extended attributes, and must be a better way to do it.
Avatar of jkr
Have you tried calling 'UpdateWindow()' after switching the orientation?
UpdateWindow has no effect.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Remember that if the shell language is like Hebrew, Arabic or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style WS_EX_RTLREADING is ignored.

Why you dont want to do it with EM_SETPARAFORMAT message ??

MAHESH
Althou I have not tried this one But One solution given on following link to replace riched32.dll with one from a computer which doesnot have VC installed to your C:\Windows\System directory and restart your system.

Refer :

http://www.codeguru.com/forum/showthread.php?t=52162 <=======

MAHESH


Thank you Dan for your comments.  I used Spy++, and the extended styles for the window when set to RTL by PreCreateWindow are identical to those which result after doing it from a menu item using ModifyStyleEx.  The style is set, according to Spy++; but the window remains doggedly LTR on the screen.

I may be driven to your other suggestion: two windows, one hidden.  Thank you for the suggestion.
Thanks Mahesh for your comments.  Copying around DLL's without knowing why sounds a bit dodgy to me!  Likewise if my window is LTR, setting individual paragraphs to RTL will work until the user pastes another bit of text in.  
Just in case...
Also check the regular style bits for both windows and (this just occurred to me) check that the default font is the same (it would be a shame if you went to the dual-window technique but it turned out that there was a simpler way...)
How I do see what the default font is, using Spy++?  I'm not at all sure that I have this set, in one case.
You can't do that with Spy++, but it is a property of the parent dialog.  I'm thinking that when the control is instantiated and created, it may refer to its parent's font... but I don't know if that is true.  The font setting might only be indirectly important...

There is an interesting info in the Remarks section of
    EM_SETBIDIOPTIONS Message
   http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_setbidioptions.asp

The last bit indicates that the control itself decides whether to change directions based on "the first strong character" (whatever that is).

Also, it mentions in passing that the default paragraph style is important.  You can try using
     CRichEditCtrl::SetParaFormat()
becasue the PARAFORMAT structure has a wAlignment value, and the wEffects has an option that set up for RTL reading... perhaps these are *the* critical items (rather than the Style bits) or perhaps they need to be set before changing the style bits.

It's a complicated issue and I have no experience with RTL stuff, so that's why I'm thrashing about... But I hope something in above helps.

-- Dan
BIDI options are for Middle Eastern Windows, tho.

I think we're going to have to accept that we can't come to an answer.  The nearest is Dan's, so I will accept that.