在form1的顶部,我做了:
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool EnableWindow(IntPtr hwnd, bool enable);
[DllImport("user32.dll")]
private static extern bool MoveWindow(IntPtr handle, int x, int y, int width,
int height, bool redraw);
然后是SW_SHOW
int SW_SHOW = 5;
然后在按钮点击事件中:
private void button1_Click(object sender, EventArgs e)
{
string[] cmdTextParts = textBox1.Text.Split(',');
foreach (string item in cmdTextParts)
{
cmdStreamWriter.WriteLine(item);
}
Process[] processlist = Process.GetProcesses();
List<string> names = new List<string>();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
if (process.MainWindowTitle.Contains("GrAD"))
{
names.Add(process.ProcessName + " " + process.Id + " " + process.MainWindowTitle);
if (process.MainWindowTitle == "GrADS 2.0.2.oga.2"))
{
IntPtr HWND = process.MainWindowHandle;
ShowWindow(HWND, SW_SHOW);
EnableWindow(HWND, true);
MoveWindow(HWND, 0, 0, 640, 480, true);
break;
}
}
}
}
}
我试图更改它在原来的5尝试4和3中的SW_SHOW,但它没有隐藏它。另一个问题是MoveWindow(HWND, 0, 0, 640, 480, true);
它没有改变窗口大小。试过100,100甚至10,10
此外它没有改变窗口位置,而是尝试使用0,0来制作500,500,但它没有改变。