【发布时间】:2015-12-30 04:31:50
【问题描述】:
我正在尝试在统一内移动我正在构建的程序的窗口。我通过对 Process.GetProcesses() 中的所有进程进行交互来处理它。然后,我调用 SetWindowPos,但没有任何反应。这是我的代码。
internal static void CheckHandle()
{
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
try
{
if (string.Equals(p.ProcessName, "TestBuild0001"))
{
_correctHandle = true;
_handle = p.Handle;
}
}
catch
{
//no catch, simply exited process
}
}
}
internal static void SetPosition()
{
if (!_correctHandle)
CheckHandle();
if (_correctHandle)
{
NewGUI.SetWarning("Window set!",5,50,900,300,50);
SetWindowPos(_handle, 0, 0, 0, 0, 0, 0x0001);
}
}
NewGUI.SetWarning 只是显示一个标签并正确显示。 _correctHandle 是一个简单的 bool,SetWindowPos 被放入为
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
private static extern bool SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
我已经尝试移动很多东西以使其正常工作,但我没有想法。尝试获取 foregroundwindow 会返回一个完全不正确的句柄,findwindow for name 会返回 0,而且还有很多其他的东西似乎不起作用。任何人都知道我的错误可能是什么/
【问题讨论】: