{"id":100295,"date":"2018-11-22T07:00:00","date_gmt":"2018-11-22T15:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=100295"},"modified":"2018-11-22T07:00:00","modified_gmt":"2018-11-22T15:00:00","slug":"how-can-i-make-a-dialog-box-right-to-left-at-runtime","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20181122-00\/?p=100295","title":{"rendered":"How can I make a dialog box right-to-left at runtime?"},"content":{"rendered":"<p><P>\nA customer had a program that decided at runtime\nwhat language to use for its user interface.\nThe customer was having trouble getting the program&#8217;s\ndialog boxes to show up with right-to-left layout\nwhen necessary.\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\n<P>\nWe are setting the\n<CODE>WS_<\/CODE><CODE>EX_<\/CODE><CODE>LAYOUT&shy;RTL<\/CODE>\nextended style in the dialog box&#8217;s\n<CODE>WM_<\/CODE><CODE>INIT&shy;DIALOG<\/CODE> message handler,\nbut\nwhat we&#8217;re seeing is\nthat although the style applies successfully,\nand the dialog itself renders RTL,\nits child elements don&#8217;t.\n<\/P>\n<DIV STYLE=\"border: solid 1px #5284bc\">\n<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" STYLE=\"color: black;background-color: white;font-size: 10pt;width: 30em;font-family: Segoe UI, Tahoma, Arial, sans-serif\">\n<TR STYLE=\"font-size: 10pt\">\n  <TD>\n    <DIV STYLE=\"padding: 0px 3px 5px 3px\">\n      <SPAN STYLE=\"font-size: 14pt\"><B>&times;<\/B><\/SPAN>\n      <SPAN>emaN a esoohC<\/SPAN>\n    <\/DIV>\n  <\/TD>\n<\/TR>\n<TR>\n <TD STYLE=\"background-color: #f0f0f0;border-top: solid 1px #dfdfdf;padding: 1em\">\n    <DIV STYLE=\"padding-bottom: 4px\">Name:<\/DIV>\n    <DIV STYLE=\"border: solid 1px black;background-color: white;padding: 3px;width: 20pc\">John Smith<\/DIV>\n    <DIV STYLE=\"padding-top: 10px\">\n    <SPAN STYLE=\"border: solid 1px #adadad\">\n        <SPAN STYLE=\"border: solid 1px #e1e1e1;background-color: #e1e1e1;padding: 2px 1em;width: 5em;text-align: center\">OK<\/SPAN>\n    <\/SPAN>\n <\/TD>\n<\/TR>\n<\/TABLE>\n<\/DIV>\n<\/BLOCKQUOTE>\n<P>\nThe actual screen shot provided by the customer\ninvolved Arabic text, but I used English text so you\ncan see which parts are running left-to-right and\nwhich parts are right-to-left.\nAlso, because I don&#8217;t know Arabic.\n<\/P>\n<P>\nThe title bar is running right-to-left, as desired,\nbut the contents of the dialog are still left-to-right.\nWhat&#8217;s going on?\n<\/P>\n<P>\nAs I&#8217;ve noted before,\n<A HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20100611-00\/?p=13743\">\nthe\n<CODE>WS_<\/CODE><CODE>EX_<\/CODE><CODE>LAYOUT&shy;RTL<\/CODE>\nextended style\nis inherited by child windows<\/A>\n(unless blocked by the\n<CODE>WS_<\/CODE><CODE>EX_<\/CODE><CODE>NO&shy;INHERIT&shy;LAYOUT<\/CODE>\nextended style).\nWhat I didn&#8217;t call out is that this inheritance occurs at the\npoint the child window is created.\nThe child window takes a snapshot of its parent window&#8217;s\nlayout;\nfuture changes to the parent window&#8217;s layout have no effect.\n<\/P>\n<P>\nThe next piece of the puzzle is realizing that the\n<CODE>WM_<\/CODE><CODE>INIT&shy;DIALOG<\/CODE> message\nis sent after the child windows have been created.\n<A HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20050331-00\/?p=36003\">\nI called this out explicitly in an earlier discussion of dialog boxes<\/A>,\nbut you already know this,\nbecause your\n<CODE>WM_<\/CODE><CODE>INIT&shy;DIALOG<\/CODE> message handler\ncalls\n<CODE>Get&shy;Dlg&shy;Item<\/CODE> to obtain handles to dialog\nchild windows in order to initialize and configure them.\n<\/P>\n<P>\nSo you need to get the\n<CODE>WS_<\/CODE><CODE>EX_<\/CODE><CODE>LAYOUT&shy;RTL<\/CODE>\nonto the window before child windows are created.\nOne way of doing this is to edit the dialog template\nand add (or remove) the\n<CODE>WS_<\/CODE><CODE>EX_<\/CODE><CODE>LAYOUT&shy;RTL<\/CODE>\nextended style\nfrom the\n<A HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20040623-00\/?p=38753\">\n<CODE>dwExStyle<\/CODE> member of the 32-bit extended header<\/A>\nbefore you call\n<CODE>Create&shy;Dialog&shy;Indirect<\/CODE> or one of its relatives.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll have to get that style change in quickly.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-100295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You&#8217;ll have to get that style change in quickly.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=100295"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/100295\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=100295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=100295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=100295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}