?
Solved

How to dynamically switch reading order in CEdit

Posted on 2006-05-04
18
Medium Priority
?
993 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:Claus
  • 9
  • 9
18 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612499
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
 

Author Comment

by:Claus
ID: 16612517
How do I send this message to the CEdit?  Can you give me an example?

Thanks,
Claus
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612532
You may use m_wndCellEdit.SendMessage(EM_SETPARAFORMAT,......

-MAHESH
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612548
0
 

Author Comment

by:Claus
ID: 16612558
But it seems it didn't work in the other thread ...
I'm having trouble using SendMessage ... can you provide an example?
0
 

Author Comment

by:Claus
ID: 16612566
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612567
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
 

Author Comment

by:Claus
ID: 16612595
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16612748
>>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
 

Author Comment

by:Claus
ID: 16613399
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
 

Author Comment

by:Claus
ID: 16613988
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16614137
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
 

Author Comment

by:Claus
ID: 16614299
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16614332
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
 

Author Comment

by:Claus
ID: 16614406
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
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 750 total points
ID: 16614464
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
 

Author Comment

by:Claus
ID: 16614485
Ok, understood !   You get the points.

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

Thanks,
Claus
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16614564
yes it will work thou i have not tried but documentation says so.

-MAHESH
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question