{"id":12683,"date":"2010-09-30T07:00:00","date_gmt":"2010-09-30T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/09\/30\/why-doesnt-the-tab-key-work-on-controls-ive-marked-as-ws_tabstop\/"},"modified":"2010-09-30T07:00:00","modified_gmt":"2010-09-30T07:00:00","slug":"why-doesnt-the-tab-key-work-on-controls-ive-marked-as-ws_tabstop","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100930-00\/?p=12683","title":{"rendered":"Why doesn&#039;t the TAB key work on controls I&#039;ve marked as WS_TABSTOP?"},"content":{"rendered":"<p>\nA customer had a programming problem regarding tab stops:\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nI create a parent window (child of main frame) as below\n<\/p>\n<pre>\n\/\/ Create the popup window that holds the toolbar.\nif (!CreateEx(\n        <b>WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT<\/b> | WS_EX_LAYERED,\n        _T(\"ToolbarPopupWindow\"),\n        _T(\"\"),\n        WS_POPUP | WS_CLIPSIBLINGS,\n        0, 0, 0, 0,\n        pParentWnd-&gt;GetSafeHwnd(),\n        NULL))\n<\/pre>\n<p>\nThis window hosts 2 toolbar windows.\nEach toolbar window\nhas the <code>WS_TABSTOP<\/code> style set using\n<code>SetWindowLong<\/code>.\n<\/p>\n<pre>\n\/\/ Set tab stop for accessibility\nDWORD dwStyles = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE);\n::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyles | WS_TABSTOP);\n<\/pre>\n<p>\nMSDN states\n<\/p>\n<blockquote><p>\n<b>WS_EX_CONTROLPARENT<\/b>\nAllows the user to navigate among the child windows of the window\nby using the TAB key.\n<\/p><\/blockquote>\n<p>\nBut I am not able to use TAB to navigate to second toolbar.\nI tried handling <code>WM_GETDLGCODE<\/code> and return\n<code>DLGC_WANTTAB<\/code>. But this message is not sent to parent.\n<\/p>\n<p>\nI can try subclassing the toolbar to handle TAB key, but if\nI do that, then what&#8217;s the point of the <code>WS_TABSTOP<\/code>\nand <code>WS_EX_CONTROLPARENT<\/code> styles?\n<\/p>\n<\/blockquote>\n<p>\nYou already know how to solve this customer&#8217;s problem.\nThe quoted documentation comes\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/61fe4bte.aspx\">\nfrom the MFC documentation on extended window styles<\/a>.\nYou may find that\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms632680.aspx\">\nthe documentation in the Platform SDK to be a bit better<\/a>.\nWhich is not unexpected,\nsince extended window styles are a Platform SDK\nfeature; MFC is merely surfacing the underlying Win32 functionality\nin its own framework.\n<\/p>\n<p>\nFinal clue:\nLook at\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/10\/21\/55384.aspx\">\nthis old blog entry<\/a>,\nbut come to it with a different point of view.\n<\/p>\n<p>\nI used my psychic powers to solve this one.\nA close reading of the description of the problem reveals\nthat the window in question is not part of a dialog box,\nwhich means that the standard dialog message loop is not active.\nWhich means that a crucial step is missing.\n<\/p>\n<blockquote CLASS=\"m\"><p>\nDid you remember to\ncall <code>IsDialogMessage<\/code> in your message loop?\n<\/p><\/blockquote>\n<p>\nThe customer confirmed that this was the missing step.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nYou are right, my window is not a dialog box.\nHandling <code>IsDialogMessage<\/code> solved the issue.\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>A customer had a programming problem regarding tab stops: I create a parent window (child of main frame) as below \/\/ Create the popup window that holds the toolbar. if (!CreateEx( WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_LAYERED, _T(&#8220;ToolbarPopupWindow&#8221;), _T(&#8220;&#8221;), WS_POPUP | WS_CLIPSIBLINGS, 0, 0, 0, 0, pParentWnd-&gt;GetSafeHwnd(), NULL)) This window hosts 2 toolbar windows. Each toolbar [&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-12683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer had a programming problem regarding tab stops: I create a parent window (child of main frame) as below \/\/ Create the popup window that holds the toolbar. if (!CreateEx( WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_LAYERED, _T(&#8220;ToolbarPopupWindow&#8221;), _T(&#8220;&#8221;), WS_POPUP | WS_CLIPSIBLINGS, 0, 0, 0, 0, pParentWnd-&gt;GetSafeHwnd(), NULL)) This window hosts 2 toolbar windows. Each toolbar [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12683","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=12683"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12683\/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=12683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=12683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=12683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}