{"id":11703,"date":"2011-01-21T07:00:00","date_gmt":"2011-01-21T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/01\/21\/modality-part-9-setting-the-correct-owner-for-modal-ui-practical-exam\/"},"modified":"2011-01-21T07:00:00","modified_gmt":"2011-01-21T07:00:00","slug":"modality-part-9-setting-the-correct-owner-for-modal-ui-practical-exam","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110121-00\/?p=11703","title":{"rendered":"Modality, part 9: Setting the correct owner for modal UI, practical exam"},"content":{"rendered":"<p>\nHere&#8217;s a question that came from a customer.\nYou can answer it yourself based on what you know about modal UI.\n(If you&#8217;re kind of rusty on the topic,\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/tags\/Modality\/default.aspx\">\nyou can catch up here<\/a>.)\nI&#8217;ve left in some irrelevant details\njust to make things interesting.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nOur program launches a helper program\nto display an Aero Wizard\nto guide the user through submitting a service request.\n<\/p>\n<pre>\ntheWiz.DoModal(hwndMainFrame);\n<\/pre>\n<p>\nThere are no <code>EnableWindow<\/code> calls leading up to\nor returning from this call.\nthe <code>DoModal<\/code> handles things nicely.\n<\/p>\n<p>\nWhen the user clicks &#8220;Cancel&#8221; to cancel the service request,\nwe use a TaskDialog so we can get the new look for our confirmation\nmessage box.\nThe task dialog setup goes like this:\n<\/p>\n<pre>\nTASKDIALOGCONFIG config = { 0 };\nconfig.cbSize = sizeof(config);\nconfig.hwndParent = hwndMainFrame;\n<\/pre>\n<p>\nWhen the user clicks &#8220;Yes&#8221; to cancel,\nthen another window instead of our frame becomes active.\n<\/p>\n<p>\nOn a hunch, I replaced the task dialog with a Win32 message box\n<\/p>\n<pre>\nMessageBox(hwndMainFrame, ...);\n<\/pre>\n<p>\nand bingo, we get the correct behavior.\nWhen our wizard exits, the main frame receives focus.\n<\/p>\n<p>\nI believe that the &#8220;automatic&#8221; modal behavior that comes\nwith <code>DoModal()<\/code> that takes care of disabling\nand reenabling the main frame is somehow getting short-circuited\nby using <code>TaskDialog<\/code> from inside our\n<code>PSM_QUERYCANCEL<\/code> message handler.\n<\/p>\n<p>\nRight now, we&#8217;ve switched to <code>MessageBox<\/code>,\nbut we would much prefer to use the task dialog.\n<\/p>\n<\/blockquote>\n<p>\nAlthough it&#8217;s not common,\nit is legal to have a window&#8217;s parent or owner\nbelongs to another thread or process.\nBut it definitely makes things a bit more tricky to manage\nbecause it attaches the input queues of the two threads,\nand you now have two threads co&ouml;perating to manage a single\nwindow hierarchy.\n<\/p>\n<p>\nIs the cross-process window hierarchy a contributing factor\nto the problem, or is it just a red herring?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a question that came from a customer. You can answer it yourself based on what you know about modal UI. (If you&#8217;re kind of rusty on the topic, you can catch up here.) I&#8217;ve left in some irrelevant details just to make things interesting. Our program launches a helper program to display an Aero [&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-11703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Here&#8217;s a question that came from a customer. You can answer it yourself based on what you know about modal UI. (If you&#8217;re kind of rusty on the topic, you can catch up here.) I&#8217;ve left in some irrelevant details just to make things interesting. Our program launches a helper program to display an Aero [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11703","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=11703"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11703\/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=11703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=11703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=11703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}