@@ -239,6 +239,15 @@ int GetAppbarAutohideEdges(HWND hwnd) {
239239 return edges;
240240}
241241
242+ void TriggerNCCalcSize (HWND hwnd) {
243+ RECT rcClient;
244+ ::GetWindowRect (hwnd, &rcClient);
245+
246+ ::SetWindowPos (hwnd, NULL , rcClient.left, rcClient.top,
247+ rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
248+ SWP_FRAMECHANGED);
249+ }
250+
242251} // namespace
243252
244253std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
@@ -369,8 +378,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
369378 // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
370379 DefWindowProcW (GetAcceleratedWidget (), WM_NCCALCSIZE, w_param, l_param);
371380
372- params->rgrc [0 ] = PROPOSED;
373- params->rgrc [1 ] = BEFORE;
381+ if (last_window_state_ == ui::SHOW_STATE_MAXIMIZED) {
382+ params->rgrc [0 ].top = 0 ;
383+ } else {
384+ params->rgrc [0 ] = PROPOSED;
385+ params->rgrc [1 ] = BEFORE;
386+ }
374387
375388 return true ;
376389 } else {
@@ -453,26 +466,15 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
453466 // window state and notify the user accordingly.
454467 switch (w_param) {
455468 case SIZE_MAXIMIZED: {
456- // Frameless maximized windows are size compensated by Windows for a
457- // border that's not actually there, so we must conter-compensate.
458- // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
459- if (!has_frame ()) {
460- float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND (
461- GetAcceleratedWidget ());
462-
463- int border =
464- GetSystemMetrics (SM_CXFRAME) + GetSystemMetrics (SM_CXPADDEDBORDER);
465- if (!thick_frame_) {
466- border -= GetSystemMetrics (SM_CXBORDER);
467- }
468- root_view_->SetInsets (gfx::Insets (border).Scale (1 .0f / scale_factor));
469- }
470-
471469 last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
472470 if (consecutive_moves_) {
473471 last_normal_bounds_ = last_normal_bounds_before_move_;
474472 }
475473
474+ if (!has_frame ()) {
475+ TriggerNCCalcSize (GetAcceleratedWidget ());
476+ }
477+
476478 NotifyWindowMaximize ();
477479 break ;
478480 }
@@ -497,8 +499,12 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
497499 switch (last_window_state_) {
498500 case ui::SHOW_STATE_MAXIMIZED:
499501 last_window_state_ = ui::SHOW_STATE_NORMAL;
500- root_view_->SetInsets (gfx::Insets (0 ));
501502 NotifyWindowUnmaximize ();
503+
504+ if (!has_frame ()) {
505+ TriggerNCCalcSize (GetAcceleratedWidget ());
506+ }
507+
502508 break ;
503509 case ui::SHOW_STATE_MINIMIZED:
504510 if (IsFullscreen ()) {
0 commit comments