Why SetWindowsPos function return false in Windows 10 and windows 11 last update?

Kuvach-5149 0 Reputation points
2023-01-11T21:29:47.77+00:00

Hi there!

I'm creating an AppBar in .net MAUI, and I want my app to sit at the top of the screen and reduce the working area. The area used by the AppBar shouldn't be covered by any other window.

I'm using the setWindowPos function(from user32.dll) to resize the working area, but it seems to work only on Windows 11 version 21H2. I also checked in Windows 10 versions 21H2, 22H2, and windows 11 version 22H2(+Patched) but setWindowPos returns false in all of them.

What might be the reason for this behavior? and what can I adjust in my code to make it work on other versions as well?

p.s: GetDesktopWindow and SystemParametersInfo are also from user32.dll

 IntPtr desktopWindow = GetDesktopWindow();
 var setPos = SetWindowPos(desktopWindow, IntPtr.Zero, 0, _APPBARHEIGHT, 0, 0, (uint)    (SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOZORDER));//only in windows 11 v21H2 return true
 RECT rect = new RECT();
 rect.Left = 0;
 rect.Top = _APPBARHEIGHT;
 rect.Right = _ScreenWidth;
 rect.Bottom = _ScreenHeight - _APPBARHEIGHT;
 var sysparam = SystemParametersInfo(0x002F, 0, ref rect, 0x0002);//return true

Thanks!

Windows development Windows API - Win32
Developer technologies .NET .NET MAUI
Windows for business Windows Client for IT Pros User experience Other
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2023-01-13T08:03:03.7766667+00:00

    You must call SetWindowPos or MoveWindow on your window handle and call SHAppBarMessage with ABM_SETPOS

    I had posted a basic sample recently in this thread : C# WinForm Making a TopBar App


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.