Пример #1
0
        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);
        }
Пример #2
0
        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;
                }
            }
        }