尽管提供了所有参数,SetWindowPos却不执行任何操作

时间:2018-11-20 20:20:25

标签: uwp dllimport setwindowpos

我已经导入了SetWindowPos和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);

我尝试使用它们,尽管GetForegroundWindow确实返回了有效值,但SetWindowPos却不做任何事情:

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

我需要设置一些功能吗?还是我忘记了权限?

插入到.NET项目中的同一代码块似乎产生了所需的结果。是否可以在UWP中实现此目的,还是必须在.NET中做到这一点?

1 个答案:

答案 0 :(得分:1)

出于各种原因,大多数User API不适用于UWP应用程序。商店也不支持它们,因此,如果您要提交应用程序,则会导致提取失败。

UWP目前有限的窗口支持,尽管我们一直在寻求改进(例如在WPF应用程序内部启用XAML控件)。