{"id":2983,"date":"2013-10-09T07:00:00","date_gmt":"2013-10-09T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/10\/09\/using-the-tab-key-to-navigate-in-non-dialogs-redux\/"},"modified":"2013-10-09T07:00:00","modified_gmt":"2013-10-09T07:00:00","slug":"using-the-tab-key-to-navigate-in-non-dialogs-redux","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20131009-00\/?p=2983","title":{"rendered":"Using the TAB key to navigate in non-dialogs, redux"},"content":{"rendered":"<p>\nYou want to use the TAB key to navigate through a non-dialog,\nso you\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/10\/21\/55384.aspx\">\ncall <code>Is&shy;Dialog&shy;Message<\/code> in your message loop<\/a>,\nbut it doesn&#8217;t work!\n<\/p>\n<pre>\n<i>\/\/ code in italics is wrong\nMSG msg;\nwhile (GetMessage(&amp;msg, NULL, 0, 0)) {\n  if (!msg.hwnd || !IsDialogMessage(msg.hwnd, &amp;msg)) {\n    TranslateMessage(&amp;msg);\n    DispatchMessage(&amp;msg);\n  }\n}<\/i>\n<\/pre>\n<p>\nThe problem here is that you are passing the wrong\nwindow handle to\n<code>Is&shy;Dialog&shy;Message<\/code>.\nThe first parameter to\n<code>Is&shy;Dialog&shy;Message<\/code>\nis the dialog-like window you want to be able to navigate through.\nBut the code above passes the window that received the message,\nso you are basically telling the control to do TAB navigation\n<i>within itself<\/i>.\nAnd naturally, the result of that is that focus <i>stays where it is<\/i>,\nbecause if you ask a button,\n&#8220;Hey, could you move to your next tab stop?&#8221;\nthe button is going to say,\n&#8220;Dude, I&#8217;m the only tab stop on my window!&#8221;\n<\/p>\n<p>\nIf you think about it,\npassing the window the message was already going to be dispatched\nto isn&#8217;t very interesting.\nIf that was the design of the function,\nthen all the work of\n<code>Is&shy;Dialog&shy;Message<\/code>\ncould&#8217;ve just been put in\n<code>Def&shy;Window&shy;Proc<\/code>\nand we wouldn&#8217;t have needed a\n<code>Is&shy;Dialog&shy;Message<\/code>\nfunction in the first place.\n<\/p>\n<p>\nAnd if you think about it,\npassing the window the message was already going to be dispatched\nto isn&#8217;t very interesting.\nIf that was the design of the function,\nthen the parameter isn&#8217;t necessary.\nThe function could just infer it directly from the\n<code>MSG<\/code> structure you passed as the second parameter.\n<\/p>\n<p>\nThe fix is to pass the main window handle to\n<code>Is&shy;Dialog&shy;Message<\/code>:\n<\/p>\n<pre>\nMSG msg;\nwhile (GetMessage(&amp;msg, NULL, 0, 0)) {\n  if (!msg.hwnd || !IsDialogMessage(<font COLOR=\"blue\">hwndFrame<\/font>, &amp;msg)) {\n    TranslateMessage(&amp;msg);\n    DispatchMessage(&amp;msg);\n  }\n}\n<\/pre>\n<p>\n<b>Reminder<\/b>:\nAs noted in the original article,\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2012\/10\/25\/10362204.aspx\">\nyou should not use the <code>WM_USER<\/code> or\n<code>WM_USER + 1<\/code> messages\nin your custom window<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You want to use the TAB key to navigate through a non-dialog, so you call Is&shy;Dialog&shy;Message in your message loop, but it doesn&#8217;t work! \/\/ code in italics is wrong MSG msg; while (GetMessage(&amp;msg, NULL, 0, 0)) { if (!msg.hwnd || !IsDialogMessage(msg.hwnd, &amp;msg)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } } The problem here is that you are [&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-2983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You want to use the TAB key to navigate through a non-dialog, so you call Is&shy;Dialog&shy;Message in your message loop, but it doesn&#8217;t work! \/\/ code in italics is wrong MSG msg; while (GetMessage(&amp;msg, NULL, 0, 0)) { if (!msg.hwnd || !IsDialogMessage(msg.hwnd, &amp;msg)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } } The problem here is that you are [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/2983","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=2983"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/2983\/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=2983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=2983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=2983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}