SetWindowPos not doing anything despite providing all parameters

519 views Asked by At

I have imported SetWindowPos and GetForegroundWindow:

[DllImport("user32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetForegroundWindow();


[DllImport("user32.dll", CharSet = CharSet.Ansi)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, UInt32 uFlags);

I have tried to use them, and while GetForegroundWindow does return a valid value, SetWindowPos does not do anything:

IntPtr hWID = GetForegroundWindow();
SetWindowPos(hWID, IntPtr.Zero, 50, 500, 800, 800, 0x0004);

Is there some capability I need to set? Or have I forgotten a permission?

It seems like the same block of code, inserted into a .NET project yields the wanted results. Is there a way to achieve this in UWP, or do I have to do this in .NET?

1

There are 1 answers

3
Peter Torr On BEST ANSWER

Most of the User APIs won't work for a UWP application, for various reasons. They are also not supported by the Store, so you would fail ingestion if you wanted to submit your app.

UWP has limited windowing support at the moment, although we're always looking to improve things (like enabling XAML controls inside of WPF apps).