A customer had a program that decided at runtime what language to use for its user interface. The customer was having trouble getting the program’s dialog boxes to show up with right-to-left layout when necessary.
We are setting the
WS_
EX_
LAYOUTRTL
extended style in the dialog box’sWM_
INITDIALOG
message handler, but what we’re seeing is that although the style applies successfully, and the dialog itself renders RTL, its child elements don’t.
× emaN a esoohC Name:John SmithOK
The actual screen shot provided by the customer involved Arabic text, but I used English text so you can see which parts are running left-to-right and which parts are right-to-left. Also, because I don’t know Arabic.
The title bar is running right-to-left, as desired, but the contents of the dialog are still left-to-right. What’s going on?
As I’ve noted before,
the
WS_
EX_
LAYOUTRTL
extended style
is inherited by child windows
(unless blocked by the
WS_
EX_
NOINHERITLAYOUT
extended style).
What I didn’t call out is that this inheritance occurs at the
point the child window is created.
The child window takes a snapshot of its parent window’s
layout;
future changes to the parent window’s layout have no effect.
The next piece of the puzzle is realizing that the
WM_
INITDIALOG
message
is sent after the child windows have been created.
I called this out explicitly in an earlier discussion of dialog boxes,
but you already know this,
because your
WM_
INITDIALOG
message handler
calls
GetDlgItem
to obtain handles to dialog
child windows in order to initialize and configure them.
So you need to get the
WS_
EX_
LAYOUTRTL
onto the window before child windows are created.
One way of doing this is to edit the dialog template
and add (or remove) the
WS_
EX_
LAYOUTRTL
extended style
from the
dwExStyle
member of the 32-bit extended header
before you call
CreateDialogIndirect
or one of its relatives.
0 comments