diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 98721b6acbf6a8b1cb2eea74091d6fa3c728b451..8a364564e4f224c6040762cb0afdd31b3bf001df 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -918,8 +918,10 @@ static QSize toNativeSizeConstrained(QSize dip, const QScreen *s)
     \internal
 */
 
-QMargins QWindowsGeometryHint::frameOnPrimaryScreen(DWORD style, DWORD exStyle)
+QMargins QWindowsGeometryHint::frameOnPrimaryScreen(const QWindow *w, DWORD style, DWORD exStyle)
 {
+	if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
+		return {};
     RECT rect = {0,0,0,0};
     style &= ~DWORD(WS_OVERLAPPED); // Not permitted, see docs.
     if (AdjustWindowRectEx(&rect, style, FALSE, exStyle) == FALSE)
@@ -932,16 +934,19 @@ QMargins QWindowsGeometryHint::frameOnPrimaryScreen(DWORD style, DWORD exStyle)
     return result;
 }
 
-QMargins QWindowsGeometryHint::frameOnPrimaryScreen(HWND hwnd)
+QMargins QWindowsGeometryHint::frameOnPrimaryScreen(const QWindow *w, HWND hwnd)
 {
-    return frameOnPrimaryScreen(DWORD(GetWindowLongPtr(hwnd, GWL_STYLE)),
+	return frameOnPrimaryScreen(w,
+                                DWORD(GetWindowLongPtr(hwnd, GWL_STYLE)),
                                 DWORD(GetWindowLongPtr(hwnd, GWL_EXSTYLE)));
 }
 
-QMargins QWindowsGeometryHint::frame(DWORD style, DWORD exStyle, qreal dpi)
+QMargins QWindowsGeometryHint::frame(const QWindow *w, DWORD style, DWORD exStyle, qreal dpi)
 {
+	if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
+		return {};
     if (QWindowsContext::user32dll.adjustWindowRectExForDpi == nullptr)
-        return frameOnPrimaryScreen(style, exStyle);
+		return frameOnPrimaryScreen(w, style, exStyle);
     RECT rect = {0,0,0,0};
     style &= ~DWORD(WS_OVERLAPPED); // Not permitted, see docs.
     if (QWindowsContext::user32dll.adjustWindowRectExForDpi(&rect, style, FALSE, exStyle,
@@ -957,16 +962,18 @@ QMargins QWindowsGeometryHint::frame(DWORD style, DWORD exStyle, qreal dpi)
     return result;
 }
 
-QMargins QWindowsGeometryHint::frame(HWND hwnd, DWORD style, DWORD exStyle)
+QMargins QWindowsGeometryHint::frame(const QWindow *w, HWND hwnd, DWORD style, DWORD exStyle)
 {
+	if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
+		return {};
     if (QWindowsScreenManager::isSingleScreen())
-        return frameOnPrimaryScreen(style, exStyle);
+		return frameOnPrimaryScreen(w, style, exStyle);
     auto screenManager = QWindowsContext::instance()->screenManager();
     auto screen = screenManager.screenForHwnd(hwnd);
     if (!screen)
         screen = screenManager.screens().value(0);
     const auto dpi = screen ? screen->logicalDpi().first : qreal(96);
-    return frame(style, exStyle, dpi);
+	return frame(w, style, exStyle, dpi);
 }
 
 // For newly created windows.
@@ -978,7 +985,7 @@ QMargins QWindowsGeometryHint::frame(const QWindow *w, const QRect &geometry,
     if (!QWindowsContext::user32dll.adjustWindowRectExForDpi
         || QWindowsScreenManager::isSingleScreen()
         || !QWindowsContext::shouldHaveNonClientDpiScaling(w)) {
-        return frameOnPrimaryScreen(style, exStyle);
+		return frameOnPrimaryScreen(w, style, exStyle);
     }
     qreal dpi = 96;
     auto screenManager = QWindowsContext::instance()->screenManager();
@@ -987,7 +994,7 @@ QMargins QWindowsGeometryHint::frame(const QWindow *w, const QRect &geometry,
         screen = screenManager.screens().value(0);
     if (screen)
         dpi = screen->logicalDpi().first;
-    return QWindowsGeometryHint::frame(style, exStyle, dpi);
+    return frame(w, style, exStyle, dpi);
 }
 
 bool QWindowsGeometryHint::handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result)
@@ -1125,7 +1132,7 @@ QRect QWindowsBaseWindow::geometry_sys() const
 
 QMargins QWindowsBaseWindow::frameMargins_sys() const
 {
-    return QWindowsGeometryHint::frame(handle(), style(), exStyle());
+    return QWindowsGeometryHint::frame(window(), handle(), style(), exStyle());
 }
 
 void QWindowsBaseWindow::hide_sys() // Normal hide, do not activate other windows.
@@ -1816,7 +1823,7 @@ QRect QWindowsWindow::normalGeometry() const
         m_savedFrameGeometry.isValid() && (window()->windowStates() & Qt::WindowFullScreen);
     const QRect frame = fakeFullScreen ? m_savedFrameGeometry : normalFrameGeometry(m_data.hwnd);
     const QMargins margins = fakeFullScreen
-        ? QWindowsGeometryHint::frame(handle(), m_savedStyle, 0)
+        ? QWindowsGeometryHint::frame(window(), handle(), m_savedStyle, 0)
         : fullFrameMargins();
     return frame.isValid() ? frame.marginsRemoved(margins) : frame;
 }
@@ -2459,7 +2466,7 @@ void QWindowsWindow::calculateFullFrameMargins()
     // Normally obtained from WM_NCCALCSIZE. This calculation only works
     // when no native menu is present.
     const auto systemMargins = testFlag(DisableNonClientScaling)
-        ? QWindowsGeometryHint::frameOnPrimaryScreen(m_data.hwnd)
+        ? QWindowsGeometryHint::frameOnPrimaryScreen(window(), m_data.hwnd)
         : frameMargins_sys();
     setFullFrameMargins(systemMargins + m_data.customMargins);
 }
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index 6cd3cd979a5234ff4fda4e22254a74bed16cf500..385534469563ee6b9a5b6429455cd84e4b121f8d 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -59,10 +59,10 @@ class QDebug;
 
 struct QWindowsGeometryHint
 {
-    static QMargins frameOnPrimaryScreen(DWORD style, DWORD exStyle);
-    static QMargins frameOnPrimaryScreen(HWND hwnd);
-    static QMargins frame(DWORD style, DWORD exStyle, qreal dpi);
-    static QMargins frame(HWND hwnd, DWORD style, DWORD exStyle);
+	static QMargins frameOnPrimaryScreen(const QWindow *w, DWORD style, DWORD exStyle);
+	static QMargins frameOnPrimaryScreen(const QWindow *w, HWND hwnd);
+	static QMargins frame(const QWindow *w, DWORD style, DWORD exStyle, qreal dpi);
+	static QMargins frame(const QWindow *w, HWND hwnd, DWORD style, DWORD exStyle);
     static QMargins frame(const QWindow *w, const QRect &geometry,
                           DWORD style, DWORD exStyle);
     static bool handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result);
