{"id":45381,"date":"2015-06-15T07:00:00","date_gmt":"2015-06-15T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20150615-00\/?p=45381\/"},"modified":"2019-03-13T12:16:21","modified_gmt":"2019-03-13T19:16:21","slug":"20150615-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150615-00\/?p=45381\/","title":{"rendered":"How can I reposition my window so it isn&#8217;t covered by the touch keyboard?"},"content":{"rendered":"<p><a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2015\/06\/08\/10620180.aspx\">Last week<\/a>, we saw how we could rearrange our window contents to avoid having the touch keyboard cover the edit control. But what if the touch keyboard covers the entire window? No amount of rearranging will help. We&#8217;ll have to move our window. <\/p>\n<p>Let&#8217;s make these changes to the <code>Do&shy;Layout<\/code> function: <\/p>\n<pre>\nvoid\nDoLayout(HWND hwnd, int cx, int cy, bool isKeyboardShowing = false)\n{\n  ...\n  if (g_hwndChild) {\n    ...\n      if (IntersectRect(&amp;rc, &amp;rcEdit, &amp;rcKeyboardClient)) {\n        <font COLOR=\"blue\">if (rcKeyboardClient.top &gt; 50) {<\/font>\n          cyEdit = min(rcKeyboardClient.top, cy);\n        <font COLOR=\"blue\">} else if (isKeyboardShowing) {\n          \/\/ need to reposition the entire window, ugh.\n          int dyAdjust = 50 - rcKeyboardClient.top;\n          RECT rcWindow;\n          GetWindowRect(hwnd, &amp;rcWindow);\n          SetWindowPos(hwnd, nullptr,\n            rcWindow.left, rcWindow.top - dyAdjust, 0, 0,\n            SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);\n          return;\n        }<\/font>\n      }\n      ...\n}\n<\/pre>\n<p>If there are at least 50 pixels of the edit control visible, then we consider that good enough. If not, and if we are responding to the keyboard showing, then we take matters into our own hands and <i>move our window<\/i> so that there are 50 pixels of the edit control visible. I didn&#8217;t bother adding a check to make sure we never moved beyond the top of the work area; I&#8217;ll leave that as an exercise for the reader, seeing as it&#8217;s more typing that tends to distract from the point of the article. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Taking it a step further.<\/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-45381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Taking it a step further.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/45381","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=45381"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/45381\/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=45381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=45381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=45381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}