How to dynamically switch reading order in CEdit

I have been struggling to switch reading order in a CEdit, trying for instance:

m_wndCellEdit.ModifyStyleEx(WS_EX_LTRREADING, WS_EX_RTLREADING, 0);
m_wndCellEdit.ModifyStyleEx(WS_EX_LEFT, WS_EX_RIGHT, 0);
m_wndCellEdit.InvalidateRect( NULL, false );

and

LONG lAlign = GetWindowLong( m_wndCellEdit.m_hWnd, GWL_EXSTYLE);
lAlign ^= WS_EX_RIGHT;
lAlign ^= WS_EX_RTLREADING;
SetWindowLong( m_wndCellEdit.m_hWnd, GWL_EXSTYLE, lAlign);
m_wndCellEdit.InvalidateRect( NULL, false );

But nothing works. The CEdit remains with LTR reading order. I want to be able to switch dynamically between LTR and RTL but it doesn't seem to be possible?

Can anyone help? I urgently need a solution.

Thanks,
Claus

ClausAsked:
Who is Participating?
 
mahesh1402Commented:
As I said only copy paste string that is in another language will not get this worked.. Controls will not detect that string is in another langauge and will reast to that as RTL.. Your control should be successfully set style RTL which you can have in Arabic window version otherwise style will be ignored.

-MAHESH
0
 
mahesh1402Commented:
WS_EX_RTLREADING : If the shell language is 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 is ignored and not treated as an error.

Try to Use the EM_SETPARAFORMAT message.  Set PFE_RTLPARA in the PARAFORMAT2 structure when sending EM_SETPARAFORMAT

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

-MAHESH
0
 
ClausAuthor Commented:
How do I send this message to the CEdit?  Can you give me an example?

Thanks,
Claus
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
mahesh1402Commented:
You may use m_wndCellEdit.SendMessage(EM_SETPARAFORMAT,......

-MAHESH
0
 
mahesh1402Commented:
0
 
ClausAuthor Commented:
But it seems it didn't work in the other thread ...
I'm having trouble using SendMessage ... can you provide an example?
0
 
ClausAuthor Commented:
I did the following but it still doesn't work:

            PARAFORMAT2 p;
            p.dwMask = PFM_RTLPARA;
            p.cbSize = sizeof( PARAFORMAT2 );
            m_wndCellEdit.SendMessage( EM_SETPARAFORMAT, 0, (LPARAM)&p );

0
 
mahesh1402Commented:
PARAFORMAT2 paraFmt;

 ::ZeroMemory(&paraFmt, sizeof(PARAFORMAT2));

  paraFmt.cbSize = sizeof(PARAFORMAT2);
  paraFmt.wEffects = PFM_RTLPARA;
  .....
  m_wndCellEdit.SendMessage(EM_SETPARAFORMAT, 0L, reinterpret_cast<LPARAM>(&paraFmt));

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

-MAHESH

0
 
ClausAuthor Commented:
I modified my code to match yours but it still doesn't work.

Also, it didn't seem to work in the other thread ... so are you sure it should work?

Someone in the other thread indicated that possibly these styles can only be modified when the CEdit is created. Could this be true?

Claus

0
 
mahesh1402Commented:
>>Someone in the other thread indicated that possibly these styles can only be modified when the CEdit is created. Could this be true?

yeah you may give that try....

used CreateEx rather than Create to create Edit control; not knowing that the CreateEx simply calls ModifyStyleEx AFTER the control is already created...So instead  override the PreCreateWindow class and set the style:

BOOL CMyEditCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
   cs.dwExStyle |= WS_EX_RTLREADING;
   return CMyEditCtrl::PreCreateWindow(cs);
}

-MAHESH
0
 
ClausAuthor Commented:
Unfortunately this is not what I need. I could do this already. I do need the dynamic modification of the control but perhaps it just isn't possible.

Claus
0
 
ClausAuthor Commented:
Ok, perhaps I have to accept that I must have a special Arabic version of my software if I cannot switch layout dynamically.

I have made such a version now using all the above tricks. So text is now displayed in the right side of my CEdit's. However, if I use Google translate to get me some Arabic text and copy/paste it into the CEdit, it is reversed.

Why is this?

If you help me resolve this, I will give you the points?

0
 
mahesh1402Commented:
You dont have arabic version of software... SO just copy / paste arabic text in your editbox will not help you to display your text right to left order as your control is not supporting RTL order yet....

I think it seems deriving your own control from CEdit and customizing it is the only solutions for this..

-MAHESH
0
 
ClausAuthor Commented:
If I installed the Arabic version of MS Visual, I could get it?

Or are you saying my application would work correctly on an Arabic version of Windows?

0
 
mahesh1402Commented:
Yes I am saying saying my application would work correctly on an Arabic version of Windows.. As doumentation states as said above  :

WS_EX_RTLREADING : If the shell language is 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 is ignored and not treated as an error

-MAHESH
0
 
ClausAuthor Commented:
Isn't there a way I can set my Windows up to this?

Or at least one of the applications?   I copied from Internet Explorer, and that was reversed.

0
 
ClausAuthor Commented:
Ok, understood !   You get the points.

Do you think it's possible the dynamic behavior would work under Arabic windows?

Thanks,
Claus
0
 
mahesh1402Commented:
yes it will work thou i have not tried but documentation says so.

-MAHESH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.