Link to home
Start Free TrialLog in
Avatar of Claus
Claus

asked on

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

Avatar of mahesh1402
mahesh1402
Flag of India image

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
Avatar of Claus
Claus

ASKER

How do I send this message to the CEdit?  Can you give me an example?

Thanks,
Claus
You may use m_wndCellEdit.SendMessage(EM_SETPARAFORMAT,......

-MAHESH
Avatar of Claus

ASKER

But it seems it didn't work in the other thread ...
I'm having trouble using SendMessage ... can you provide an example?
Avatar of Claus

ASKER

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 );

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

Avatar of Claus

ASKER

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

>>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
Avatar of Claus

ASKER

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
Avatar of Claus

ASKER

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?

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
Avatar of Claus

ASKER

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?

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
Avatar of Claus

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India 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
Avatar of Claus

ASKER

Ok, understood !   You get the points.

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

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

-MAHESH