{"id":4323,"date":"2013-05-17T07:00:00","date_gmt":"2013-05-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/05\/17\/who-sends-the-initial-wm_updateuistate-message\/"},"modified":"2013-05-17T07:00:00","modified_gmt":"2013-05-17T07:00:00","slug":"who-sends-the-initial-wm_updateuistate-message","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130517-00\/?p=4323","title":{"rendered":"Who sends the initial WM_UPDATEUISTATE message?"},"content":{"rendered":"<p><P>\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/05\/16\/10419105.aspx\">\nLast time<\/A>,\nwe looked at the\nconfusingly-named\n<CODE>WM_UPDATE&shy;UI&shy;STATE<\/CODE>\nand\n<CODE>WM_CHANGE&shy;UI&shy;STATE<\/CODE>\nmessages.\nBut how does the whole indicator thingie get off the ground?\n<\/P>\n<P>\nThe default state for a window is to show all indicators.\nBut as a special trick,\nthe dialog manager will send a\n<CODE>WM_UPDATE&shy;UI&shy;STATE<\/CODE> message\nwith <CODE>UIS_INITIALIZE<\/CODE> after the dialog\nhas been initialized,\nwhich turns off the indicators if the last input event\nwas a mouse event.\nThis is its way of inferring whether the dialog box was\ntriggered by a mouse or keyboard action\nand setting the initial indicators accordingly.\n(Note that if the user checked\n<I>Underline keyboard shortcuts and access keys<\/I>,\nthen the dialog manager leaves the indicators enabled\nregardless of the last input event.)\n<\/P>\n<P>\nThat special\n<CODE>WM_UPDATE&shy;UI&shy;STATE<\/CODE> message\nis what gives dialog boxes the extra special feature\nof hiding the keyboard accelerators until you use the keyboard.\n<\/P>\n<P>\nBut notice that only the dialog manager does this.\nIf you want this behavior in your own non-dialog windows,\nyou will need to send the message yourself.\n<\/P>\n<PRE>\nBOOL MyWindow::OnCreate(&#8230;)\n{\n &#8230; create and initialize any child windows &#8230;<\/p>\n<p> <FONT COLOR=\"blue\">\/\/ initialize indicators\n BOOL fAlwaysUnderline = FALSE;\n SystemParametersInfo(SPI_GETKEYBOARDCUES, 0,\n                      &amp;fAlwaysUnderline, 0);\n if (!fAlwaysUnderline) {\n  SendMessage(this-&gt;m_hwnd, WM_UPDATEUISTATE,\n              MAKEWPARAM(UIS_INITIALIZE, 0), 0);\n }<\/FONT>\n}\n<\/PRE>\n<P>\n<B>Exercise<\/B>:\nWhy is it important to create and initialize the child windows\nbefore sending the\n<CODE>WM_UPDATE&shy;UI&shy;STATE<\/CODE> message?\n<\/P>\n<P>\n<B>Exercise<\/B>:\nWhy can&#8217;t the window manager do this automatically\nafter <CODE>WM_CREATE<\/CODE> returns?\n<\/P>\n<P>\n<B>Exercise<\/B>:\nExplain the behavior this customer observes.\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\nWe have a dialog box with three buttons.\nSometimes the dialog displays underlines for the hotkeys,\nand sometimes it doesn&#8217;t.\nI know about the feature which hides keyboard accelerators\nby default, but that doesn&#8217;t explain why the setting gets\nignored sometimes.\nThe first time I show the dialog in my program,\nI get the underlines, but the second and subsequent times,\nI do not.\n<\/BLOCKQUOTE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, we looked at the confusingly-named WM_UPDATE&shy;UI&shy;STATE and WM_CHANGE&shy;UI&shy;STATE messages. But how does the whole indicator thingie get off the ground? The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE&shy;UI&shy;STATE message with UIS_INITIALIZE after the dialog has been initialized, which [&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-4323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Last time, we looked at the confusingly-named WM_UPDATE&shy;UI&shy;STATE and WM_CHANGE&shy;UI&shy;STATE messages. But how does the whole indicator thingie get off the ground? The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE&shy;UI&shy;STATE message with UIS_INITIALIZE after the dialog has been initialized, which [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4323","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=4323"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4323\/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=4323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=4323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=4323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}