private void UpdateProcessLabel() { PV ps = (PV)processCombo.SelectedItem; if (ps != null && !ps.p.HasExited) { IntPtr h = ps.p.MainWindowHandle; if (h != IntPtr.Zero) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.length = Marshal.SizeOf(wp); if (GetWindowPlacement(h, ref wp)) { processLabel.Text = wp.ToString(); } else { processLabel.Text = "could not get window placement!"; } } else { processLabel.Text = "no main window!"; } } else { processLabel.Text = "no process!"; } }
private void ApplyProcessClicked(object s, EventArgs e) { PV ps = (PV)processCombo.SelectedItem; R res = (R)processResCombo.SelectedItem; if (ps != null) { IntPtr h = ps.p.MainWindowHandle; if (h != IntPtr.Zero) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.length = Marshal.SizeOf(wp); if (GetWindowPlacement(h, ref wp)) { Console.WriteLine("updating size"); if (SetWindowPos(h, 0, wp.normPos.left, wp.normPos.top, res.x, res.y, 0)) { UpdateProcessLabel(); } else { MessageBox.Show("could not set window position!"); } } else { MessageBox.Show("could not get window placement!"); } } } }
private void QueryProcessClicked(object s, EventArgs e) { processLabel.Text = ""; processCombo.BeginUpdate(); PV prev = (PV)processCombo.SelectedItem; processCombo.Items.Clear(); List <PV> list = new List <PV>(); foreach (Process p in Process.GetProcesses()) { IntPtr h = p.MainWindowHandle; if (h != IntPtr.Zero) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.length = Marshal.SizeOf(wp); GetWindowPlacement(h, ref wp); if (wp.showCmd == SW_SHOWNORMAL) { string t = p.MainWindowTitle; if (t.Length == 0) { t = "#" + p.ProcessName; } list.Add(new PV(p, t + " [" + p.Id + "]")); } } } list.Sort(); processCombo.Items.AddRange(list.ToArray()); if (prev != null) { foreach (object i in processCombo.Items) { if (((PV)i).p.Id == prev.p.Id) { processCombo.SelectedItem = i; break; } } } processCombo.EndUpdate(); }