相关疑难解决方法(0)

将SetWindowPos与多个监视器一起使用

使用user32.dllC#,我编写了下面看到的方法。使用窗口的处理手柄,它将在指定{x,y}位置设置窗口位置。

但是,在多监视器环境中,下面的代码仅将窗口位置设置为主监视器。我也希望能够选择哪个显示器。
有人可以解释一下如何使用SetWindowPos或结合其他user32.dll功能来实现吗?

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

private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_SHOWWINDOW = 0x0040;

public static void SetWindowPosition(Process p, int x, int y)
{
    IntPtr handle = p.MainWindowHandle;
    if (handle != IntPtr.Zero)
    {
        SetWindowPos(handle, IntPtr.Zero, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW); …
Run Code Online (Sandbox Code Playgroud)

c# windows user32

2
推荐指数
1
解决办法
1099
查看次数

标签 统计

c# ×1

user32 ×1

windows ×1