public EDGlassForm(System.Diagnostics.Process follow) { this.Opacity = 1.0; // Tweak as desired this.FormBorderStyle = FormBorderStyle.None; this.BackColor = Color.Black; this.ControlBox = false; this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.Manual; this.AutoScaleMode = AutoScaleMode.None; this.ClientSize = new Size(100, 100); this.DoubleBuffered = true; this.Name = "EDMC Overlay Window"; this.Text = this.Name; this.TopMost = true; this.TransparencyKey = Color.Black; int initialStyle = WindowUtils.GetWindowLong(this.Handle, WindowUtils.GWL_EXSTYLE); // makes window click-trough WindowUtils.SetWindowLong(this.Handle, WindowUtils.GWL_EXSTYLE, initialStyle | WindowUtils.WS_EX_LAYERED | WindowUtils.WS_EX_TRANSPARENT | WindowUtils.WS_EX_NOACTIVATE); this.Follow = follow; // Disable Aero transitions, the plexiglass gets too visible if (Environment.OSVersion.Version.Major >= 6) { int value = 1; if (follow != null) { WindowUtils.DwmSetWindowAttribute(follow.MainWindowHandle, WindowUtils.DWMWA_TRANSITIONS_FORCEDISABLED, ref value, 4); } } }
private static string GetActiveWindowTitle() { const int nChars = 256; StringBuilder Buff = new StringBuilder(nChars); IntPtr handle = WindowUtils.GetForegroundWindow(); if (WindowUtils.GetWindowText(handle, Buff, nChars) > 0) { return(Buff.ToString()); } return(null); }
public void FollowWindow() { if (Follow == null) { return; } if (this.InvokeRequired) { this.Invoke(new Action(() => { FollowWindow(); })); } else { RECT window = new RECT(); Point pos = new Point(300, 300); Size siz = new Size(640, 400); this.TopMost = true; if (Process.GetCurrentProcess().Id != Follow.Id && WindowUtils.GetWindowRect(Follow.MainWindowHandle, ref window)) { pos = new Point(window.Left + this.XOffset, window.Top + this.YOffset); siz = new Size( window.Right - window.Left - (2 * this.XOffset), window.Bottom - window.Top - (2 * this.YOffset)); if (HalfSize) { pos.X = siz.Width / 3; pos.Y = siz.Height / 3; siz.Height = siz.Height / 2; siz.Width = siz.Width / 2; } } if (forceLocation.HasValue && forceSize.HasValue) { pos = forceLocation.Value; siz = forceSize.Value; } this.Location = pos; this.ClientSize = siz; } }
private void StartUpdate() { var bufg = BufferedGraphicsManager.Current; DateTime lastframe = DateTime.Now; Graphics draw = null; Logger.LogMessage("Starting update loop"); double fixedwait = (1000 / FPS); // number of msec to wait assuming zero time to draw frame while (this.run) { if (back == null) { allocateBuffers(bufg); } TimeSpan elapsed = DateTime.Now.Subtract(lastframe); double wait = fixedwait - elapsed.TotalMilliseconds; if (wait > 0) { System.Threading.Thread.Sleep((int)fixedwait); } if (Glass == null) { System.Threading.Thread.Sleep(1000); } if (Glass != null) { Glass.XOffset = VIRTUAL_ORIGIN_X; Glass.YOffset = VIRTUAL_ORIGIN_Y; if (this.ForceLocation.HasValue && this.ForceSize.HasValue) { Glass.ForceGeometry(this.ForceLocation.Value, this.ForceSize.Value); } if (Glass.Follow != null && Glass.Follow.HasExited) { Logger.LogMessage(String.Format("{0} has exited. quitting.", Glass.Follow.ProcessName)); System.Environment.Exit(0); } if (draw == null) { draw = getDraw(); } if (Graphics == null || draw == null) { Thread.Sleep(500); continue; } IntPtr activeWindow = WindowUtils.GetForegroundWindow(); bool foreground = (activeWindow == Glass.Follow.MainWindowHandle); if (foreground) { Debug.WriteLine(DateTime.Now + " window foreground"); } else { Debug.WriteLine(DateTime.Now + " window obscured"); } bool render = (foreground && (Graphics.Values.Count > 0)) || this.ForceRender; if (render) { lock (Graphics) { Draw(draw); swapBuffers(bufg); Glass.FollowWindow(); } } else { // nothing to draw, clear and sleep a long sleep Clear(draw); swapBuffers(bufg); Thread.Sleep(1000); } lastframe = DateTime.Now; } } }