{"id":14353,"date":"2010-04-12T07:00:00","date_gmt":"2010-04-12T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/04\/12\/how-do-i-switch-a-window-between-normal-and-fullscreen\/"},"modified":"2010-04-12T07:00:00","modified_gmt":"2010-04-12T07:00:00","slug":"how-do-i-switch-a-window-between-normal-and-fullscreen","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100412-00\/?p=14353","title":{"rendered":"How do I switch a window between normal and fullscreen?"},"content":{"rendered":"<p>\nFrederic Delhoume wants to know\nif there is\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#1237990\">\na simple example of code that switches an application\nfrom windowed to fullscreen<\/a>.\nHe then included a code fragment that did some crazy things with\nparent windows and hiding and showing.\n<\/p>\n<p>\nYou&#8217;re making it way, way harder than it needs to be.\nLet&#8217;s start with our\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/a> and make these changes:\n<\/p>\n<pre>\nWINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };\nvoid OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)\n{\n  DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);\n  if (dwStyle &amp; WS_OVERLAPPEDWINDOW) {\n    MONITORINFO mi = { sizeof(mi) };\n    if (GetWindowPlacement(hwnd, &amp;g_wpPrev) &amp;&amp;\n        GetMonitorInfo(MonitorFromWindow(hwnd,\n                       MONITOR_DEFAULTTOPRIMARY), &amp;mi)) {\n      SetWindowLong(hwnd, GWL_STYLE,\n                    dwStyle &amp; ~WS_OVERLAPPEDWINDOW);\n      SetWindowPos(hwnd, HWND_TOP,\n                   mi.rcMonitor.left, mi.rcMonitor.top,\n                   mi.rcMonitor.right - mi.rcMonitor.left,\n                   mi.rcMonitor.bottom - mi.rcMonitor.top,\n                   SWP_NOOWNERZORDER | SWP_FRAMECHANGED);\n    }\n  } else {\n    SetWindowLong(hwnd, GWL_STYLE,\n                  dwStyle | WS_OVERLAPPEDWINDOW);\n    SetWindowPlacement(hwnd, &amp;g_wpPrev);\n    SetWindowPos(hwnd, NULL, 0, 0, 0, 0,\n                 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |\n                 SWP_NOOWNERZORDER | SWP_FRAMECHANGED);\n  }\n}\n\/\/ add to WndProc\n    HANDLE_MSG(hwnd, WM_LBUTTONUP, OnLButtonUp);\n<\/pre>\n<p>\nTo avoid getting into the intricacies of hotkeys and accelerators,\nI opted to toggle to fullscreen on a click.\nWhen the\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/12\/16\/1305524.aspx\">\nbutton goes up<\/a>,\nwe check\nwhether we are currently in normal mode or fullscreen mode\nby sniffing at our window styles.\nIf we are in normal mode, we save the current window placement\nand get the dimensions of the current monitor.\nAnd then the magic happens:\nWe remove the caption and other decorations from our window style\nand reposition the window so it covers the entire monitor.\nAn important flag to pass here is <code>SWP_FRAME&shy;CHANGED<\/code>,\nwhich tells the window manager to recalculate the window decorations\n(which we need it to do because we just changed them).\n<\/p>\n<p>\nWhen returning from fullscreen, we just undo what we had done\nwhen we went fullscreen:\nWe restore the caption and other decorations to our window\nand restore the original window state.\n<\/p>\n<p>\nAnd that&#8217;s all there is to it.\nYou don&#8217;t have to do anything special to get the taskbar\nto &#8220;get out of the way&#8221;; the taskbar recognizes when applications\nhave gone fullscreen and automatically gets out of the way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Frederic Delhoume wants to know if there is a simple example of code that switches an application from windowed to fullscreen. He then included a code fragment that did some crazy things with parent windows and hiding and showing. You&#8217;re making it way, way harder than it needs to be. Let&#8217;s start with our scratch [&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-14353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Frederic Delhoume wants to know if there is a simple example of code that switches an application from windowed to fullscreen. He then included a code fragment that did some crazy things with parent windows and hiding and showing. You&#8217;re making it way, way harder than it needs to be. Let&#8217;s start with our scratch [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14353","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=14353"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14353\/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=14353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=14353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=14353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}