Window positioning leads to space around windows in Windows 10

I have a code that positions windows to display quadrants. It works fine on Windows XP, 7 and 8 / 8.1. However, in Windows 10 there is a strange gap between the windows. Additional space surrounds the window on all sides. I suppose this has something to do with the borders of the window, but cannot figure out how to fix the problem. Any input would be greatly appreciated. The code is as follows:

// Get monitor info HMONITOR hm = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mi; mi.cbSize = sizeof(mi); GetMonitorInfo(hm, &mi); // Set screen coordinates and dimensions of monitor work area DWORD x = mi.rcWork.left; DWORD y = mi.rcWork.top; DWORD w = mi.rcWork.right - x; DWORD h = mi.rcWork.bottom - y; switch (corner) { case 0: // Left top SetWindowPos(hWnd, HWND_TOP, x, y, w / 2, h / 2, SWP_NOZORDER); break; case 1: // Right top SetWindowPos(hWnd, HWND_TOP, x + w / 2, y, w / 2, h / 2, SWP_NOZORDER); break; case 2: // Right bottom SetWindowPos(hWnd, HWND_TOP, x + w / 2, y + h / 2, w / 2, h / 2, SWP_NOZORDER); break; case 3: // Left bottom SetWindowPos(hWnd, HWND_TOP, x, y + h / 2, w / 2, h / 2, SWP_NOZORDER); break; } 
+7
windows winapi
source share
2 answers

I managed to fix this effect by inflating the target rectangle on the calculated stock as follows:

 static RECT GetSystemMargin(IntPtr handle) { HResult success = DwmGetWindowAttribute(handle, DwmApi.DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out var withMargin, Marshal.SizeOf<RECT>()); if (!success.Succeeded) { Debug.WriteLine($"DwmGetWindowAttribute: {success.GetException()}"); return new RECT(); } if (!GetWindowRect(handle, out var noMargin)) { Debug.WriteLine($"GetWindowRect: {new Win32Exception()}"); return new RECT(); } return new RECT { left = withMargin.left - noMargin.left, top = withMargin.top - noMargin.top, right = noMargin.right - withMargin.right, bottom = noMargin.bottom - withMargin.bottom, }; } 

And then doing

 RECT systemMargin = GetSystemMargin(this.Handle); targetBounds.X -= systemMargin.left; targetBounds.Y -= systemMargin.top; targetBounds.Width += systemMargin.left + systemMargin.right; targetBounds.Height += systemMargin.top + systemMargin.bottom; 

This worked for all windows on which I could test it, except for Explorer windows, which I hard-coded for exception. If I make this extension on the conductor near the edge of the screen, the window will end spilling a large area past it onto the neighboring monitor.

0
source share

The default font size for Windows XP / 7/8 / 8.1 is 100% by default, but Windows 10 displays text and elements at 125% by default. This directly affects all window sizes.

Go to the settings, display, and you will find the scroller, move it 100%, and everything should display just like in Windows 8/7 / XP

-3
source share

All Articles