{"id":102996,"date":"2019-10-15T07:00:00","date_gmt":"2019-10-15T14:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/oldnewthing\/?p=102996"},"modified":"2019-10-14T17:03:03","modified_gmt":"2019-10-15T00:03:03","slug":"20191015-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20191015-00\/?p=102996","title":{"rendered":"How should I create controls on my dialog box that has a tab control?"},"content":{"rendered":"<p>The tab control from the shell common controls provides the tab selector control that is popular in tabbed dialogs. You&#8217;d be tempted to create the content of the tab control&#8217;s display area as children of the tab control, but that&#8217;s the wrong thing to do.<\/p>\n<p>You should create them as <i>siblings<\/i> of the tab control.<\/p>\n<p>What you want to do is create your tab control to cover the portion of the dialog box that you want to be tabbed. You then use the <code>TCM_<\/code><code>ADJUST\u00adRECT<\/code> message (or the equivalent <code>TabCtrl_<\/code><code>AdjustRect<\/code> macro) to determine the display area of the tab control. Inside that display area, you can place your content, but do it with the dialog box as the parent, not the tab control.<\/p>\n<table style=\"border-collapse: collapse; text-align: center;\" title=\"Dialog box at root of tree with three children: Tab control, content 1, and content 2\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Dialog<\/td>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 12em; border-right: solid 1px black;\" colspan=\"4\">\u00a0<\/td>\n<td style=\"width: 12em;\" colspan=\"4\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em; border-right: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 9em; border-right: solid 1px black; border-top: solid 1px black;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 9em; border-right: solid 1px black; border-top: solid 1px black;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Tab control<\/td>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Content 1<\/td>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Content 2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Depending on which tab in the tab control is selected, you show exactly one of the content windows and hide the others.<\/p>\n<p>If you think about how focus works in dialog boxes, you&#8217;ll realize that it has to be this way.<\/p>\n<p>The tab control itself is focusable, and presumably you want to be able to put focus on your content, too. Now consider what happens if you create the content as children of the tab control:<\/p>\n<table style=\"border-collapse: collapse; text-align: center;\" title=\"Dialog box at root of tree with one child: Tab control. Tab control has two children: Content 1, and content 2, the content boxes have dotted borders\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Dialog<\/td>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 12em; border-right: solid 1px black;\" colspan=\"4\">\u00a0<\/td>\n<td style=\"width: 12em;\" colspan=\"4\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Tab control<\/td>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 12em; border-right: solid 1px black;\" colspan=\"4\">\u00a0<\/td>\n<td style=\"width: 12em;\" colspan=\"4\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 6em; border-right: solid 1px black;\" colspan=\"2\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; border-left: solid 1px black;\" colspan=\"2\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: dotted 1px black;\" colspan=\"2\">Content 1<\/td>\n<td style=\"width: 6em;\" colspan=\"2\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: dotted 1px black;\" colspan=\"2\">Content 2<\/td>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>By default, the tab order in a dialog box follows the dialog box&#8217;s immediate children. In this case, it means that the tab control can receive focus, but the content cannot, since they are not immediate children of the dialog box.<\/p>\n<p>You can alter this behavior with the <code>WS_<\/code><code>EX_<\/code><code>CONTROL\u00adPARENT<\/code> extended window style, which means &#8220;<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120620-00\/?p=7333\">I&#8217;m just a container. My children are the things that can get focus, not me<\/a>.&#8221; So let&#8217;s try that and put the <code>WS_<\/code><code>EX_<\/code><code>CONTROL\u00adPARENT<\/code> extended window style on the tab control.<\/p>\n<table style=\"border-collapse: collapse; text-align: center;\" title=\"Dialog box at root of tree with one child: Tab control. Tab control has two children: Content 1, and content 2, the tab control has a dotted border\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Dialog<\/td>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 12em; border-right: solid 1px black;\" colspan=\"4\">\u00a0<\/td>\n<td style=\"width: 12em;\" colspan=\"4\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: dotted 1px black;\" colspan=\"2\">Tab control<\/td>\n<td style=\"width: 9em;\" colspan=\"3\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 12em; border-right: solid 1px black;\" colspan=\"4\">\u00a0<\/td>\n<td style=\"width: 12em;\" colspan=\"4\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 6em; border-right: solid 1px black;\" colspan=\"2\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 3em; border-top: solid 1px black;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; border-left: solid 1px black;\" colspan=\"2\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Content 1<\/td>\n<td style=\"width: 6em;\" colspan=\"2\">\u00a0<\/td>\n<td style=\"width: 6em; height: 2em; border: solid 1px black;\" colspan=\"2\">Content 2<\/td>\n<td style=\"width: 3em;\" colspan=\"1\">\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This time, the tab control drops out of the tab order, and its children, the content controls, join in.<\/p>\n<p>With this window hierarchy, no amount of fiddling with the <code>WS_<\/code><code>EX_<\/code><code>CONTROL\u00adPARENT<\/code> extended window style will allow the tab control <i>and<\/i> its children to all be part of the tab order. Because a window and its children cannot both be part of the tab order.<\/p>\n<p>The only solution is to move the content controls out, so they aren&#8217;t children of the tab control. Making them siblings of the tab control, as they are in the original diagram, allows all three to participate in the tab order.<\/p>\n<p><b>Bonus chatter<\/b>: The content windows are typically nested dialogs which are marked with the <code>WS_<\/code><code>EX_<\/code><code>CONTROL\u00adPARENT<\/code> extended window style. This permits the children of the nested dialogs to participate in the tab order, but keeping them inside a nested dialog lets you hide and show the controls in bulk by hiding and showing the nested dialog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>They are siblings of the tab control, not children.<\/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-102996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>They are siblings of the tab control, not children.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102996","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=102996"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102996\/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=102996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=102996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=102996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}