Click here to Skip to main content
14,607,863 members

Setting Write Direction and Alignment

Rate this:
5.00 (5 votes)
Please Sign up or sign in to vote.
5.00 (5 votes)
4 Jul 2020CPOL
How to set write direction and alignment
Here is a tip how to set the writing direction (RTL or LTR) along with the alignment of a CEdit control.


Sometimes, you want your CEdit control to be set to the language used, which can be Left to Right (default) or Right to Left.

  • Arabic
  • Aramaic
  • Azeri
  • Dhivehi/Maldivian
  • Hebrew
  • Kurdish (Sorani)
  • Persian/Farsi
  • Urdu

See this article for further reading.

Using the Code

Assuming your control name is m_MyEdit, here is the code:

void MyDialog::SetLangDirection(bool RTL)
    wprintf(L"Setting language direction to %s", (RTL) ? L"right to left" : L"left to right");
    DWORD w_dwStyle;

    w_dwStyle = GetWindowLong(m_MyEdit.GetSafeHwnd(), GWL_EXSTYLE);

    if (RTL)
        w_dwStyle -= WS_EX_LEFT | WS_EX_LTRREADING;
        w_dwStyle |= WS_EX_RIGHT | WS_EX_RTLREADING;
        w_dwStyle -= WS_EX_RIGHT | WS_EX_RTLREADING;
        w_dwStyle |= WS_EX_LEFT | WS_EX_LTRREADING;

    SetWindowLong(m_MyEdit.GetSafeHwnd(), GWL_EXSTYLE, w_dwStyle);

When you press the RTL button, you should be able to see text aligned to the right, with RTL writing direction:

Image 1

If you press the LTR, the text will be aligned to the left with LTR writing direction:

Image 2


  • 4th July, 2020: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michael Haephrati
CEO Secured Globe, Inc.
United States United States
Michael Haephrati, Musician and CEO and co-founder of Secured Globe, Inc. Worked on many ventures starting from HarmonySoft, designing Rashumon, the first Graphical Multi-lingual word processor for Amiga computer. During 1995-1996 he worked as a Contractor with Apple at Cupertino.

Can be hired here for freelancing work.

Comments and Discussions

Questionhi Pin
Member 148839938-Jul-20 0:50
MemberMember 148839938-Jul-20 0:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 4 Jul 2020

Tagged as


1 bookmarked