Esempio n. 1
0
        /* Loop method */
        private void ListenLoop()
        {
            while (listening)
            {
                // Copy current foreground window title and window rect
                String    previousForegroundWindowTitle = CurrentForegroundWindowTitle;
                Rectangle previousForegroundWindowRect  = CurrentForegroundWindowRect;

                // Retrieve window handle
                IntPtr handle = GetForegroundWindowHandle();

                // Update current foreground window title and window rect
                CurrentForegroundWindowTitle  = Window.GetWindowTitleFromHandle(handle);
                CurrentForegroundWindowRect   = Window.GetWindowRectFromHandle(handle);
                CurrentForegroundWindowHandle = handle;

                // Title Different?
                if (CurrentForegroundWindowTitle != String.Empty && CurrentForegroundWindowTitle != previousForegroundWindowTitle)
                {
                    // Notify handler
                    handler.NewForegroundWindow(CurrentForegroundWindowTitle, CurrentForegroundWindowRect, handle);

                    // Check if the window actually exists
                    currentWindowExists = Window.Exists(CurrentForegroundWindowTitle);
                }

                // Rectangle different?
                if (!CurrentForegroundWindowRect.Equals(previousForegroundWindowRect))
                {
                    // Notify
                    handler.ForegroundWindowPositionChanged(CurrentForegroundWindowTitle, CurrentForegroundWindowRect);
                }

                // Check the windows that have been specifically added to our list, one by one
                CheckWindowsMonitorList();

                // Wait
                Thread.Sleep(ListenInterval);
            }
        }
Esempio n. 2
0
        private Rectangle GetForegroundWindowRect()
        {
            IntPtr handle = GetForegroundWindowHandle();

            return(Window.GetWindowRectFromHandle(handle));
        }