• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1030
  • Last Modified:

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

0
roger_pearse
Asked:
roger_pearse
  • 7
  • 5
  • 3
  • +1
1 Solution
 
mahesh1402Commented:
try like this :

rCtrl.ModifyStyleEx( WS_EX_LTRREADING, WS_EX_RTLREADING );


MAHESH
0
 
mahesh1402Commented:
oops
0
 
roger_pearseAuthor Commented:
Thanks, but this doesn't work either.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

0
 
roger_pearseAuthor Commented:
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.
0
 
jkrCommented:
Have you tried calling 'UpdateWindow()' after switching the orientation?
0
 
roger_pearseAuthor Commented:
UpdateWindow has no effect.
0
 
DanRollinsCommented:
Only some styles and extended styles can be changed dynamically -- a few of them can only be set at creation time.  I suspect that you have uncovered one of them...

To see if that is the case, call
    GetExStyleEx()
right after calling ModifyStyleEx() and verify that the requested change took place.

Another thought:  Perhaps the WS_EX_LTRREADING might be incompatible with other settings.  For instance, if WS_EX_LEFTSCROLLBAR  is in effect, then the RichEdit handler may decide to ignore the requested change.

What I suggest is that you create a RTL RE control, then use Spy++ (or GetWindowLong) to examine its styles.  Write them down.   Then create a LTR window and when you do the ModifyStyleEx thing, be sure to set all of them.   That might not work (it may be impossible to dynaically change) but its worth a try.

=--=-=-=-=-=-=
If this turns out to be "just one of those style settings" that cannot be changed dynamically, then you still have a remaining option:  Destroy the control and recreate it in the same location.  You would need to save and restore the text, the selection, and the scroll position (and maybe more...) but if it is important, then it can be done -- probably with just a short flicker.  (alternative option:  Create both types but hide the one that is not in use, then on a switch request, synchronize their states and hide the current one and unhide the hidden one).

-- Dan
0
 
mahesh1402Commented:
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
0
 
mahesh1402Commented:
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


0
 
roger_pearseAuthor Commented:
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.
0
 
roger_pearseAuthor Commented:
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.  
0
 
DanRollinsCommented:
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...)
0
 
roger_pearseAuthor Commented:
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.
0
 
DanRollinsCommented:
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
0
 
roger_pearseAuthor Commented:
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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now