private void button2_Click(object sender, EventArgs e) { //Find MineSweeper Window System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("winmine"); if (p.Length == 0) { //No MineSweeper Window found DialogResult result = MessageBox.Show("No active MineSweeper Window Found! Open a new one?", "Window Detection Error", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Process winmine = new Process(); winmine.StartInfo.FileName = "winmine.exe"; winmine.Start(); System.Threading.Thread.Sleep(500); } } p = System.Diagnostics.Process.GetProcessesByName("winmine"); if (p.Length > 0) { //MineSweeper Window found, activate and set as foreground window SetForegroundWindow(p[0].MainWindowHandle); //Get Window Info (Get Window Size) WINDOWINFO mine_window; GetWindowInfo(p[0].MainWindowHandle, out mine_window); Size s = mine_window.rcWindow.Size; s.Width = mine_window.rcWindow.Width; s.Height = mine_window.rcWindow.Height; MoveWindow(p[0].MainWindowHandle, 0, 0, s.Width, s.Height, true); //Display Window Size and Position textBox1.Text = mine_window.rcWindow.Height.ToString(); textBox2.Text = mine_window.rcWindow.Width.ToString(); textBox3.Text = mine_window.rcWindow.X.ToString(); textBox4.Text = mine_window.rcWindow.Y.ToString(); } }