0

With the help of CWnd::SetWindowText method, I am able to set the desired caption, to my dailog based application. How can I make it left/right aligned?

Andrew Komiagin
  • 6,446
  • 1
  • 13
  • 23
Programmer
  • 329
  • 2
  • 6
  • 25

2 Answers2

3

To right-align dialog title, you need to set "Right Align Text" for the Dialog in the resource editor (corresponding extended style is WS_EX_RIGHT).

The WS_EX_LAYOUTRT style actually flips the dialog, so all controls are layed out from right-to-left. Title DOES get to the right, but the close button moves to the left. NOT what was asked in the original question.

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
1

There are few extended window styles like WS_EX_RIGHT to do that.

Here is a sample:

int CTestAlignDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialogEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    ModifyStyleEx(0, WS_EX_LAYOUTRTL | WS_EX_RTLREADING);

    return 0;
}
Andrew Komiagin
  • 6,446
  • 1
  • 13
  • 23
  • Do I have to edit .rc file for the same? Or using a method I need to change the style? – Programmer Nov 18 '15 at 09:18
  • You can call `ModifyStyleEx` for this window to do that. – Andrew Komiagin Nov 18 '15 at 09:19
  • I tried something of this sort in rc file: STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU |WS_EX_LEFT and also tried: ModifyStyleEx(0,WS_EX_LEFT); Both in vain – Programmer Nov 18 '15 at 09:37
  • You might be interested in WS_EX_RTLREADING and WS_EX_LTRREADING styles. – Andrew Komiagin Nov 18 '15 at 10:17
  • Just wanted a sample on how to use it, because ModifyStyleEx(0,WS_EX_LEFT) or ModifyStyleEx(0,WS_EX_LTRREADING); doesnt seems to be working. – Programmer Nov 18 '15 at 10:21
  • I've updated the answer to provide you with code snippet – Andrew Komiagin Nov 18 '15 at 10:37
  • @Programmer: Both `WS_EX_LEFT` and `WS_EX_LTRREADING` have a value of `0x0`. So in other words, they are the default settings. Trying to remove those styles is futile. It just results in a no-op. You'll have to actually **add** the respective styles you want to use. Irrespective, all alignment styles are ignored unless you use a language that supports reading-order alignment (like Hebrew or Arabic). – IInspectable Nov 18 '15 at 11:05