Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 5308

How can I make a dialog box right-to-left at runtime?

$
0
0


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_LAYOUT­RTL
extended style in the dialog box's
WM_INIT­DIALOG 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 Smith



OK





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_LAYOUT­RTL
extended style
is inherited by child windows

(unless blocked by the
WS_EX_NO­INHERIT­LAYOUT
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_INIT­DIALOG 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_INIT­DIALOG message handler
calls
Get­Dlg­Item to obtain handles to dialog
child windows in order to initialize and configure them.



So you need to get the
WS_EX_LAYOUT­RTL
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_LAYOUT­RTL
extended style
from the

dwExStyle member of the 32-bit extended header

before you call
Create­Dialog­Indirect or one of its relatives.


Viewing all articles
Browse latest Browse all 5308

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>