{"id":7333,"date":"2012-06-20T07:00:00","date_gmt":"2012-06-20T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/06\/20\/when-embedding-a-dialog-inside-another-make-sure-you-dont-accidentally-create-duplicate-control-ids\/"},"modified":"2012-06-20T07:00:00","modified_gmt":"2012-06-20T07:00:00","slug":"when-embedding-a-dialog-inside-another-make-sure-you-dont-accidentally-create-duplicate-control-ids","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120620-00\/?p=7333","title":{"rendered":"When embedding a dialog inside another, make sure you don&#039;t accidentally create duplicate control IDs"},"content":{"rendered":"<p>The <code>WS_EX_CONTROL&shy;PARENT<\/code> extended style (<a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/07\/30\/201988.aspx\">known in dialog templates as <code>DS_CONTROL<\/code><\/a>) instructs the dialog manager that the dialog&#8217;s children should be promoted into the dialog&#8217;s parent. This is easier to explain in pictures than in text. Given the following window hierarchy:<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"The root dialog has four children, labeled A, B, C, and D. The second child B is marked WS_EX_CONTROLPARENT and has two children of its own, labeled B1 and B2.\">\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"5\" style=\"width: 15em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     hdlgMain<\/td>\n<td colspan=\"5\" style=\"width: 15em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"5\" style=\"width:15em;border-bottom: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"5\" style=\"width:15em;border-bottom: solid black .75pt\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-left: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"4\" style=\"width:12em\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-left: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     A<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     B<br \/><code><font size=\"-1\">WS_EX_CON-<br \/>TROLPARENT<\/font><\/code><\/td>\n<td colspan=\"2\" style=\"width: 6em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     C<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     D<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 6em\">&nbsp;<\/td>\n<td colspan=\"2\" style=\"border-bottom: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"2\" style=\"border-bottom: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"6\" style=\"width:15em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 6em\">&nbsp;<\/td>\n<td colspan=\"4\" style=\"border-left: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"6\" style=\"width:15em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     B1<\/td>\n<td colspan=\"2\" style=\"width: 6em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     B2<\/td>\n<td colspan=\"6\" style=\"width:15em\">&nbsp;<\/td>\n<\/tr>\n<\/table>\n<p> The result of the <code>WS_EX_CONTROL&shy;PARENT<\/code> extended style being set is that the children of&nbsp;B are treated as if they were direct children of the main dialog, and the window&nbsp;B itself logically vanishes.<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"The root dialog has five children, labeled A, B1, B2, C, and D.\">\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"6\" style=\"width: 15em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     hdlgMain<\/td>\n<td colspan=\"6\" style=\"width: 15em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"6\" style=\"width:18em;border-bottom: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"6\" style=\"width:18em;border-bottom: solid black .75pt\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-left: solid black .75pt;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-right: solid black .75pt\">&nbsp;<\/td>\n<td colspan=\"3\" style=\"width: 9em;border-right: solid black .75pt\">&nbsp;<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     A<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     B1<\/td>\n<td colspan=\"1\" style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     B2<\/td>\n<td colspan=\"1\" style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     C<\/td>\n<td style=\"width: 3em\">&nbsp;<\/td>\n<td colspan=\"2\" align=\"center\" style=\"border: solid black .75pt;height: 3em;width: 6em\">     D<\/td>\n<\/tr>\n<\/table>\n<p> The <code>WS_EX_CONTROL&shy;PARENT<\/code> extended style means &#8220;Hello, I am not really a dialog control. I am a control parent. In other words, I have children, and <i>those children<\/i> are controls.&#8221; (Some people erroneously put the <code>WS_EX_CONTROL&shy;PARENT<\/code> extended style on the main dialog itself. That&#8217;s wrong, but fortunately it also has no effect.)\n Okay, this is all stuff you already know. So why am I bringing up this topic? I sort of gave it away in the subject line: When you use <code>WS_EX_CONTROL&shy;PARENT<\/code>, you need to be careful that the controls that you are promoting into the parent don&#8217;t conflict with controls already in the parent, or with controls promoted into the parent by another sibling.\n Suppose, in the above scenario, that window&nbsp;C also had the <code>WS_EX_CONTROL&shy;PARENT<\/code> extended style, and it had children C1&nbsp;and&nbsp;C2. Not only do you have to watch out that B1 and B2 don&#8217;t conflict with the controls A or D, you also have to watch out that it doesn&#8217;t conflict with C1 or C2 either.\n &#8220;But <a href=\"http:\/\/wikiality.wikia.com\/Mr._Wizard\"> Mister Wizard<\/a>, the property sheet control hosts multiple child dialogs, and since they can be provided by third parties, it&#8217;s entirely possible (and likely) that there will be conflicts between B1 and, say, C2. Why doesn&#8217;t this create a problem?&#8221;<\/p>\n<p> Well, Timmy, most of the time, it doesn&#8217;t, because notifications are fired to the control&#8217;s parent, and in the case of child dialogs, the child dialog&#8217;s child controls fire their notifications to the child dialog. So as long as the identifiers are unique within the child dialog, you won&#8217;t have a problem. This isn&#8217;t the entire answer, however, but to understand it further, we&#8217;ll need to look at another consequence of control ID conflicts, which we&#8217;ll take up next time. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The WS_EX_CONTROL&shy;PARENT extended style (known in dialog templates as DS_CONTROL) instructs the dialog manager that the dialog&#8217;s children should be promoted into the dialog&#8217;s parent. This is easier to explain in pictures than in text. Given the following window hierarchy: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hdlgMain &nbsp; [&hellip;]<\/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-7333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The WS_EX_CONTROL&shy;PARENT extended style (known in dialog templates as DS_CONTROL) instructs the dialog manager that the dialog&#8217;s children should be promoted into the dialog&#8217;s parent. This is easier to explain in pictures than in text. Given the following window hierarchy: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hdlgMain &nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7333","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=7333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7333\/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=7333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}