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.
- Kurdish (Sorani)
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");
w_dwStyle = GetWindowLong(m_MyEdit.GetSafeHwnd(), GWL_EXSTYLE);
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:
If you press the LTR, the text will be aligned to the left with LTR writing direction:
- 4th July, 2020: Initial version