{"id":35723,"date":"2005-05-03T07:00:00","date_gmt":"2005-05-03T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/05\/03\/managing-the-ui-state-of-accelerators-and-focus-rectangles\/"},"modified":"2005-05-03T07:00:00","modified_gmt":"2005-05-03T14:00:00","slug":"managing-the-ui-state-of-accelerators-and-focus-rectangles","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050503-00\/?p=35723","title":{"rendered":"Managing the UI state of accelerators and focus rectangles"},"content":{"rendered":"<p>\nStarting with Windows&nbsp;2000,\nkeyboard indicators such as underlined accelerators and\nfocus rectangles (collectively known as &#8220;keyboard cues&#8221;)\nare hidden by default, and are revealed only when you start\nusing the keyboard.\nYou can control this behavior from the Desktop Control Panel,\nunder Appearance, Effects, &#8220;Hide underlined letters for keyboard\nnavigation until I press the Alt key&#8221;.\n<\/p>\n<p>\nNote that this setting actually controls both underlined letters\nand focus rectangles, even though the text describes only one\nof the effects.  Underlines are hidden until you press the Alt key,\nand focus rectangles are hidden until you either press the Alt key\nor press the Tab key.\n<\/p>\n<p>\nHere&#8217;s how it works.\n<\/p>\n<p>\nThere are three UI state mesages:\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardaccelerators\/keyboardacceleratorreference\/keyboardacceleratormessages\/wm_changeuistate.asp\">\n<code>WM_CHANGEUISTATE<\/code><\/a>,\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardaccelerators\/keyboardacceleratorreference\/keyboardacceleratormessages\/wm_queryuistate.asp\">\n<code>WM_QUERYUISTATE<\/code><\/a>\nand\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardaccelerators\/keyboardacceleratorreference\/keyboardacceleratormessages\/wm_updateuistate.asp\">\n<code>WM_UPDATEUISTATE<\/code><\/a>.\nThe third one is, in my opinion, a misnomer.\nIt really should be called something like <code>WM_UISTATECHANGED<\/code>\nsince it is a notification that something has happened, not\na message that you send to cause something to happen.\n<\/p>\n<p>\nWhen a dialog box or menu is displayed via a mouse click,\nkeyboard cues are hidden; if the dialog box or menu was displayed\nvia a keypress, then keyboard cues are visible.\nThis decision is made by sending a\n<code>WM_CHANGEUISTATE<\/code> message to the root window with the\n<code>UIS_INITIALIZE<\/code> flag.\nThis is done automatically by the dialog manager, but if you&#8217;re\ndoing your own custom windows, you&#8217;ll have to send it yourself.\n<\/p>\n<p>\nThe <code>WM_CHANGEUISTATE<\/code> message bubbles up to the\ntop-level window, which changes the window UI state accordingly,\nthen broadcasts a <code>WM_UPDATEUISTATE<\/code> message to all its child windows\nto notify them that the state has changed.\n(Of course, if the <code>WM_CHANGEUISTATE<\/code> message has no effect&mdash;for\nexample, hiding something that is already hidden&mdash;then the\n<code>WM_UPDATEUISTATE<\/code> message is optimized out since the entire operation\nis a no-op.)\n<\/p>\n<p>\nWhen a window that draws keyboard cues\nreceives a <code>WM_UPDATEUISTATE<\/code> message,\nit typically invalidates itself so that the cues can be redrawn\/erased,\ndepending on the new state.\n<\/p>\n<p>\nAt drawing time, a window that draws keyboard cues can use the\n<code>WM_QUERYUISTATE<\/code> message to determine which keyboard cues are\nvisible and which are hidden, and draw its content accordingly.\nIf focus rectangles are hidden, then the window should skip the call\nto the <code>DrawFocusRect<\/code> function.\nIf keyboard underlines are hidden, then the window suppresses\nunderlines in its text drawing.  If the window uses\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/gdi\/fontext_0odw.asp\">\nthe <code>DrawText<\/code> function<\/a>,\nit can pass the <code>DT_HIDEPREFIX<\/code> flag\nto suppress the underlines.\nIf you are responding to\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/commctls\/comboboxes\/comboboxreference\/comboboxmessages\/wm_drawitem.asp\">\nthe <code>WM_DRAWITEM<\/code><\/a>\nmessage, then you should check for the\n<code>ODS_NOACCEL<\/code> and <code>ODS_NOFOCUSRECT<\/code> flags\nto determine\nwhether\nyou should draw an underline accelerator or a focus rectangle.\n<\/p>\n<p>\nFinally, during execution you may discover that the user has used\nthe keyboard to perform navigation within your control.\nFor example, the listview control may have noticed that the user has used\nthe arrow keys to change the selected item.\nWhen this happens, the control sends itself a <code>WM_CHANGEUISTATE<\/code> specifying\nwhich keyboard cues should be revealed.\nAs noted above, the <code>WM_CHANGEUISTATE<\/code> message eventually causes all the\nwindows in the window tree to receive a <code>WM_UPDATEUISTATE<\/code> message\nif their states need to change.\n<\/p>\n<p>\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/dialogboxes\/dialogboxreference\/dialogboxfunctions\/isdialogmessage.asp\">\nThe <code>IsDialogMessage<\/code> function<\/a>\nsends\n<code>WM_CHANGEUISTATE<\/code> messages as appropriate, so dialog boxes\nand anybody else who uses <code>IsDialogMessage<\/code> gets\nkeyboard-cues tracking for free.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The three UI state messages: WM_CHANGEUISTATE, WM_QUERYUISTATE and WM_UPDATEUISTATE.<\/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-35723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The three UI state messages: WM_CHANGEUISTATE, WM_QUERYUISTATE and WM_UPDATEUISTATE.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35723","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=35723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35723\/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=35723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}