private void ShowInformation(NativeWindowModoki window) { showing = window; pbxScreen.Refresh(); edtTitle.Text = window.Text; edtClass.Text = window.ClassName; cbxProcess.Text = "Process: " + window.ProcessName; cbxLocation.Text = string.Format("Location: {0}, {1}", window.Left, window.Top); cbxSize.Text = string.Format("Size: {0} x {1}", window.Width, window.Height); if (!LoadSetting(window.Text, window.ClassName, window.ProcessName)) { cbxTitle.Checked = false; cbxTitleRegex.Checked = false; cbxClass.Checked = false; cbxClassRegex.Checked = false; cbxLocation.Checked = false; cbxSize.Checked = false; } cbxTitle.Enabled = true; edtTitle.Enabled = cbxTitle.Checked && cbxTitleRegex.Checked; cbxTitleRegex.Enabled = cbxTitle.Checked; cbxClass.Enabled = true; edtClass.Enabled = cbxClass.Checked && cbxClassRegex.Checked; cbxClassRegex.Enabled = cbxClass.Checked; cbxLocation.Enabled = true; cbxSize.Enabled = true; btnSave.Enabled = cbxLocation.Checked || cbxSize.Checked; }
private void ClearInformation() { showing = null; cbxTitle.Text = "Title: "; edtTitle.Text = ""; cbxClass.Text = "Class: "; edtClass.Text = ""; cbxProcess.Text = "Process: "; cbxLocation.Text = "Location: "; cbxSize.Text = "Size: "; cbxTitle.Checked = false; cbxTitleRegex.Checked = false; cbxClass.Checked = false; cbxClassRegex.Checked = false; cbxLocation.Checked = false; cbxSize.Checked = false; cbxTitle.Enabled = false; edtTitle.Enabled = false; cbxTitleRegex.Enabled = false; cbxClass.Enabled = false; edtClass.Enabled = false; cbxClassRegex.Enabled = false; cbxLocation.Enabled = false; cbxSize.Enabled = false; btnSave.Enabled = false; }
private void DrawWindow(Graphics g, NativeWindowModoki window, Brush brush) { var screen = Screen.AllScreens[currentScreen]; var x = (float)((window.Left - screen.Bounds.Left) / scale); var y = (float)((window.Top - screen.Bounds.Top) / scale); var width = (float)(window.Width / scale); var height = (float)(window.Height / scale); g.FillRectangle(brush, x, y, width, height); g.DrawRectangle(Pens.DarkGray, x, y, width, height); g.DrawString(window.Text, SystemFonts.DefaultFont, Brushes.Black, x + 1, y + 1); }
private NativeWindowModoki GetToplevelWindow(IntPtr hwnd) { if (hwnd == IntPtr.Zero) { return(null); } var tgt = new NativeWindowModoki(hwnd); while (tgt != null && (tgt.Style & NativeWindowModoki.WS_CHILD) != 0) { tgt = tgt.Parent; } return(tgt); }
private void pbxScreen_MouseClick(object sender, MouseEventArgs e) { var found = showing == null; NativeWindowModoki first = null; foreach (var window in Enumerable.Reverse(windows)) { var screen = Screen.AllScreens[currentScreen]; var left = (float)((window.Left - screen.Bounds.Left) / scale); var top = (float)((window.Top - screen.Bounds.Top) / scale); var right = left + (float)(window.Width / scale); var bottom = top + (float)(window.Height / scale); if (e.Location.X >= left && e.Location.X <= right && e.Location.Y >= top && e.Location.Y <= bottom) { if (showing == window) { found = true; continue; } if (!found) { if (first == null) { first = window; } continue; } ShowInformation(window); return; } } if (first != null) { ShowInformation(first); } }
private void UpdateScreenInfo() { lblScreenName.Text = string.Format("Screen {0}", currentScreen + 1); btnPrevScreen.Enabled = currentScreen > 0; btnNextScreen.Enabled = currentScreen < screenCount - 1; SetupPictureBox(); windows.Clear(); EnumWindows((hwnd, lParam) => { var window = new NativeWindowModoki(hwnd); if (window.Visible && (window.Style & NativeWindowModoki.WS_CHILD) == 0 && window.Width > 0 && window.Height > 0 && window.Text != "Program Manager") { windows.Add(window); } return(true); }, IntPtr.Zero); foreach (var window in windows) { NativeWindowModoki.POINT[] points = { new NativeWindowModoki.POINT { x = window.Left, y = window.Top }, new NativeWindowModoki.POINT { x = window.Right, y = window.Top }, new NativeWindowModoki.POINT { x = window.Left, y = window.Bottom }, new NativeWindowModoki.POINT { x = window.Right, y = window.Bottom }, }; for (var i = 0; i < points.Length; i++) { var tgt = GetToplevelWindow(WindowFromPoint(points[i])); if (tgt != null) { window.FrontWindows[i] = tgt.Handle; } } // top side if (window.FrontWindows[0] == IntPtr.Zero && window.FrontWindows[1] == IntPtr.Zero) { var tgt1 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Left, y = window.Top - 1 })); var tgt2 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Right, y = window.Top - 1 })); if (tgt1 != null && tgt2 != null && tgt1.Handle == tgt2.Handle) { window.BackWindows[0] = tgt1.Handle; } } // bottom side if (window.FrontWindows[2] == IntPtr.Zero && window.FrontWindows[3] == IntPtr.Zero) { var tgt1 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Left, y = window.Top + 1 })); var tgt2 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Right, y = window.Top + 1 })); if (tgt1 != null && tgt2 != null && tgt1.Handle == tgt2.Handle) { window.BackWindows[1] = tgt1.Handle; } } // left side if (window.FrontWindows[0] == IntPtr.Zero && window.FrontWindows[2] == IntPtr.Zero) { var tgt1 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Left - 1, y = window.Top })); var tgt2 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Right - 1, y = window.Top })); if (tgt1 != null && tgt2 != null && tgt1.Handle == tgt2.Handle) { window.BackWindows[2] = tgt1.Handle; } } // right side if (window.FrontWindows[1] == IntPtr.Zero && window.FrontWindows[3] == IntPtr.Zero) { var tgt1 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Left + 1, y = window.Top })); var tgt2 = GetToplevelWindow(WindowFromPoint(new NativeWindowModoki.POINT { x = window.Right + 1, y = window.Top })); if (tgt1 != null && tgt2 != null && tgt1.Handle == tgt2.Handle) { window.BackWindows[3] = tgt1.Handle; } } } windows.Sort((a, b) => { if (a.FrontWindows.Contains(b.Handle) || b.BackWindows.Contains(a.Handle)) { return(-1); } else if (b.FrontWindows.Contains(a.Handle) || a.BackWindows.Contains(b.Handle)) { return(1); } else { return(0); } }); ClearInformation(); pbxScreen.Refresh(); }