Gary698346
Gary698346

Reputation: 51

SetWindowPlacement not moving certain windows

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?

Upvotes: 3

Views: 400

Answers (1)

Gary698346
Gary698346

Reputation: 51

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

Upvotes: 2

Related Questions