@@ -306,22 +306,29 @@ set_properties_now(WindowProperties &properties) {
306306 LPoint2i bottom_right = top_left + _properties.get_size ();
307307
308308 DWORD window_style = make_style (_properties);
309+ DWORD current_style = GetWindowLong (_hWnd, GWL_STYLE);
309310 SetWindowLong (_hWnd, GWL_STYLE, window_style);
310311
311- // Now calculate the proper size and origin with the new window style.
312- RECT view_rect;
313- SetRect (&view_rect, top_left[0 ], top_left[1 ],
314- bottom_right[0 ], bottom_right[1 ]);
315- WINDOWINFO wi;
316- GetWindowInfo (_hWnd, &wi);
317- AdjustWindowRectEx (&view_rect, wi.dwStyle , FALSE , wi.dwExStyle );
318-
319- // We need to call this to ensure that the style change takes effect.
320- SetWindowPos (_hWnd, HWND_NOTOPMOST, view_rect.left , view_rect.top ,
321- view_rect.right - view_rect.left ,
322- view_rect.bottom - view_rect.top ,
323- SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
324- SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
312+ // If we switched to/from undecorated, calculate the new size.
313+ if (((window_style ^ current_style) & WS_CAPTION) != 0 ) {
314+ RECT view_rect;
315+ SetRect (&view_rect, top_left[0 ], top_left[1 ],
316+ bottom_right[0 ], bottom_right[1 ]);
317+ WINDOWINFO wi;
318+ GetWindowInfo (_hWnd, &wi);
319+ AdjustWindowRectEx (&view_rect, wi.dwStyle , FALSE , wi.dwExStyle );
320+
321+ SetWindowPos (_hWnd, HWND_NOTOPMOST, view_rect.left , view_rect.top ,
322+ view_rect.right - view_rect.left ,
323+ view_rect.bottom - view_rect.top ,
324+ SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
325+ SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
326+ } else {
327+ // We need to call this to ensure that the style change takes effect.
328+ SetWindowPos (_hWnd, HWND_NOTOPMOST, 0 , 0 , 0 , 0 ,
329+ SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE |
330+ SWP_FRAMECHANGED | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
331+ }
325332 }
326333
327334 if (properties.has_title ()) {
@@ -402,6 +409,23 @@ set_properties_now(WindowProperties &properties) {
402409 properties.clear_minimized ();
403410 }
404411
412+ if (properties.has_maximized ()) {
413+ if (_properties.get_maximized () != properties.get_maximized ()) {
414+ if (properties.get_maximized ()) {
415+ ShowWindow (_hWnd, SW_MAXIMIZE);
416+ } else {
417+ ShowWindow (_hWnd, SW_RESTORE);
418+ }
419+ _properties.set_maximized (properties.get_maximized ());
420+
421+ if (_properties.get_minimized ()) {
422+ // Immediately minimize it again
423+ ShowWindow (_hWnd, SW_MINIMIZE);
424+ }
425+ }
426+ properties.clear_maximized ();
427+ }
428+
405429 if (properties.has_fullscreen ()) {
406430 if (properties.get_fullscreen () && !is_fullscreen ()) {
407431 if (do_fullscreen_switch ()){
@@ -507,6 +531,7 @@ open_window() {
507531 }
508532 bool want_foreground = (!_properties.has_foreground () || _properties.get_foreground ());
509533 bool want_minimized = (_properties.has_minimized () && _properties.get_minimized ()) && !want_foreground;
534+ bool want_maximized = (_properties.has_maximized () && _properties.get_maximized ()) && want_foreground;
510535
511536 HWND old_foreground_window = GetForegroundWindow ();
512537
@@ -533,6 +558,9 @@ open_window() {
533558 if (want_minimized) {
534559 ShowWindow (_hWnd, SW_MINIMIZE);
535560 ShowWindow (_hWnd, SW_MINIMIZE);
561+ } else if (want_maximized) {
562+ ShowWindow (_hWnd, SW_MAXIMIZE);
563+ ShowWindow (_hWnd, SW_MAXIMIZE);
536564 } else {
537565 ShowWindow (_hWnd, SW_SHOWNORMAL);
538566 ShowWindow (_hWnd, SW_SHOWNORMAL);
@@ -854,6 +882,21 @@ handle_reshape() {
854882 << " ," << properties.get_y_size () << " )\n " ;
855883 }
856884
885+ // Check whether the window has been maximized or unmaximized.
886+ WINDOWPLACEMENT pl;
887+ pl.length = sizeof (WINDOWPLACEMENT);
888+ if (GetWindowPlacement (_hWnd, &pl)) {
889+ if (pl.showCmd == SW_SHOWMAXIMIZED || (pl.flags & WPF_RESTORETOMAXIMIZED) != 0 ) {
890+ properties.set_maximized (true );
891+ } else {
892+ properties.set_maximized (false );
893+ }
894+ }
895+ else if (windisplay_cat.is_debug ()) {
896+ windisplay_cat.debug ()
897+ << " GetWindowPlacement() failed in handle_reshape. Ignoring.\n " ;
898+ }
899+
857900 adjust_z_order ();
858901 system_changed_properties (properties);
859902}
@@ -1083,6 +1126,9 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
10831126bool WinGraphicsWindow::
10841127open_graphic_window () {
10851128 DWORD window_style = make_style (_properties);
1129+ if (_properties.get_maximized ()) {
1130+ window_style |= WS_MAXIMIZE;
1131+ }
10861132
10871133 wstring title;
10881134 if (_properties.has_title ()) {
0 commit comments