Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetWindowPlacement not moving certain windows

Tags:

windows

winapi

I'm writing a Windows 10 C# program to save and restore the positions and sizes of open windows (whether displayed or minimized). The following loop has worked on almost all windows, but not the Resource Monitor or Computer Management windows:

        foreach (KeyValuePair<HWND, InfoWindow> entry in openWindows)
        {
            IntPtr hWnd = entry.Key;
            Rectangle rect = entry.Value.Rect;

            WINDOWPLACEMENT wpl = new WINDOWPLACEMENT();
            if (!GetWindowPlacement(hWnd, ref wpl)) continue;

            wpl.rcNormalPosition = rect;

            SetWindowPlacement(hWnd, ref wpl);
        }

The SetWindowPlacement function seems to have no effect on the Resource Monitor or Computer Management windows' position or size. I've also tried using SetWindowPos, which also has no effect on those windows (but works on all the other windows I've tried).

Why do those particular windows behave differently? What alternative method is there to move those windows?

like image 547
Gary698346 Avatar asked Apr 09 '26 14:04

Gary698346


1 Answers

Thanks, Jonathan and Hans. That was the problem. If I run my code elevated, it works on all the windows.

like image 57
Gary698346 Avatar answered Apr 12 '26 07:04

Gary698346



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!