我有
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(string hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
我的问题是我希望能够根据标签内的文本移动特定窗口。
private void button1_Click(object sender, EventArgs e)
{
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 0X4;
const int SWP_SHOWWINDOW = 0x0040;
Process[] processes = Process.GetProcesses();
foreach (var process in processes)
{
IntPtr handle = process.MainWindowHandle;
string Text = handle.ToString();
if (handle.ToString() == WindowTextBox.Text)
{
SetWindowPos(Text, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}
}
我知道这行不通,但还是想尝试一下,我还能如何根据 WindowTextBox 中的内容移动窗口?(在 SetWindowPos(IntPtr hWnd, [...]) 中有 IntPtr 句柄并且只是改变
SetWindowPos(Text, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
到
SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
也不起作用。)有什么建议吗?