【发布时间】:2016-11-24 14:39:38
【问题描述】:
我正在尝试开发一个程序,该程序将打开 2 个 Guitar Pro 文件并将它们显示在我的多屏设置的不同屏幕上。
除了将 1 个窗口从屏幕 1 移动到屏幕 2 之外,我一切正常。
Guitar pro 有点狡猾,由于某种原因只会在屏幕 1 中打开文件...我试图通过抓住窗口句柄来移动窗口,但这只会移动主容器并将所有子窗口留在地方。我决定稍微作弊,并以编程方式移动鼠标光标以单击并将窗口从一个屏幕拖到另一个屏幕,但我仍然遇到问题......
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public void OpenFileFn()
{
Process file1 = new Process();
file1.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
file1.StartInfo.FileName = file;
file1.Start();
Thread.Sleep(500);
Process file2 = new Process();
file2.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
file2.StartInfo.FileName = file;
file2.Start();
file2.WaitForInputIdle();
Thread.Sleep(3000);
int posX = Cursor.Position.X;
int posY = Cursor.Position.Y;
SetCursorPos(-960, 15);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
SetCursorPos(960, 15);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetCursorPos(posX, posY);
}
使用上面的代码水平移动光标而不是窗口...如果我更改光标 Y 轴,则窗口垂直移动...
任何想法为什么我可以解决这个问题? 提前谢谢...
【问题讨论】:
-
你可能会更幸运SetWindowPosition,而不是尝试以编程方式重新创建鼠标拖动。
-
这似乎不是 C#。你错过了一个标签吗?还是您错过了大部分代码?
-
@nvoigt 听起来像 WPF,但代码并不完全代表 C#。
-
抱歉,已编辑第一篇文章...
-
当您说您尝试抓住窗口把手时,您究竟是如何移动窗口的?
标签: c# multiscreen