// Specifically for the video in chat windows.
        void Lync2013_IMWindow_Selection(object sender, WindowSelectionEventArgs e)
        {
            if (e.IsSelectionMade)
            {
                return;
            }

            var info = e.ActiveWindow;

            if (e.Process.ProcessName == Lync2013_IMWindow_Process && info.WindowClass == Lync2013_IMWindow_IMWindow)
            {
                // Get the last CtrlNotifySink that contains a LCC_VideoParent.
                //var sink = info.ChildWindows.First(
                //    x => x.WindowClass == Lync2013_IMWindow_CtrlNotifySink &&
                //        x.ChildWindows.Any(y => y.WindowClass == Lync2013_IMWindow_VideoParent));

                //TODO: Hm, looks like Lync 2013 does everything owner-draw so none of the child windows has any size or dimension?
                //TODO: What do we do when Lync is marked as "always on top?"
                var sink = info.ChildWindows.First(x => x.WindowClass == "NetUIHWND");

                // Check if we got a result.
                if (sink == null)
                {
                    return;
                }

                // Check that the CtrlNotifySink is visible.
                if (sink.Style.HasFlag(WindowMonitor.WindowStyles.Visible))
                {
                    // Select the video area so that we get the overlay
                    // appearing there.
                    e.Select(sink);
                }
            }
        }
        // Specifically for the video in chat windows.
        void Lync2010_IMWindow_Selection(object sender, WindowSelectionEventArgs e)
        {
            if (e.IsSelectionMade)
            {
                return;
            }

            var info = e.ActiveWindow;

            if (e.Process.ProcessName == Lync2010_IMWindow_Process && info.WindowClass == Lync2010_IMWindow_IMWindow)
            {
                // Get the last CtrlNotifySink that contains a LCC_VideoParent.
                var sink = info.ChildWindows.Last(
                    x => x.WindowClass == Lync2010_IMWindow_CtrlNotifySink &&
                    x.ChildWindows.Any(y => y.WindowClass == Lync2010_IMWindow_VideoParent));

                // Check if we got a result.
                if (sink == null)
                {
                    return;
                }

                // Check that the CtrlNotifySink is visible.
                if (sink.Style.HasFlag(WindowMonitor.WindowStyles.Visible))
                {
                    // Select the video area so that we get the overlay
                    // appearing there.
                    e.Select(sink);
                }
            }
        }
        // Specifically for the video in chat windows.
        void Lync2013_IMWindow_Selection(object sender, WindowSelectionEventArgs e)
        {
            if (e.IsSelectionMade) return;

            var info = e.ActiveWindow;
            if (e.Process.ProcessName == Lync2013_IMWindow_Process && info.WindowClass == Lync2013_IMWindow_IMWindow)
            {
                // Get the last CtrlNotifySink that contains a LCC_VideoParent.
                //var sink = info.ChildWindows.First(
                //    x => x.WindowClass == Lync2013_IMWindow_CtrlNotifySink &&
                //        x.ChildWindows.Any(y => y.WindowClass == Lync2013_IMWindow_VideoParent));

                //TODO: Hm, looks like Lync 2013 does everything owner-draw so none of the child windows has any size or dimension?
                //TODO: What do we do when Lync is marked as "always on top?"
                var sink = info.ChildWindows.First(x => x.WindowClass == "NetUIHWND");

                // Check if we got a result.
                if (sink == null) return;

                // Check that the CtrlNotifySink is visible.
                if (sink.Style.HasFlag(WindowMonitor.WindowStyles.Visible))
                {
                    // Select the video area so that we get the overlay
                    // appearing there.
                    e.Select(sink);
                }
            }
        }
        // Specifically for the video in chat windows.
        void Lync2010_IMWindow_Selection(object sender, WindowSelectionEventArgs e)
        {
            if (e.IsSelectionMade) return;

            var info = e.ActiveWindow;
            if (e.Process.ProcessName == Lync2010_IMWindow_Process && info.WindowClass == Lync2010_IMWindow_IMWindow)
            {
                // Get the last CtrlNotifySink that contains a LCC_VideoParent.
                var sink = info.ChildWindows.Last(
                    x => x.WindowClass == Lync2010_IMWindow_CtrlNotifySink &&
                        x.ChildWindows.Any(y => y.WindowClass == Lync2010_IMWindow_VideoParent));

                // Check if we got a result.
                if (sink == null) return;

                // Check that the CtrlNotifySink is visible.
                if (sink.Style.HasFlag(WindowMonitor.WindowStyles.Visible))
                {
                    // Select the video area so that we get the overlay
                    // appearing there.
                    e.Select(sink);
                }
            }
        }
        private void CheckProcess(object state)
        {
            lastRectangle = new Rect(0, 0, 0, 0);

            Process process = null;
            try
            {
                var foreground = NativeMethods.ForegroundWindow;
                process = NativeMethods.GetWindowProcess(foreground);
                var info = NativeMethods.GetWindowInformation(foreground);

                var selectWindow = SelectWindow;
                if (process != null && selectWindow != null)
                {
                    var windowArgs = new WindowSelectionEventArgs(process, info);
                    selectWindow(this, windowArgs);

                    if (windowArgs.SelectedWindow != null)
                    {
                        process.Exited += process_Exited;
                        if (!process.HasExited)
                        {
                            targetProcess = process;

                            var act = Activated;
                            if (act != null) act(this, EventArgs.Empty);

                            process = null; // Prevent dispose (see finally).
                            checkPositionTimer.Change(0, Timeout.Infinite);
                            return;
                        }
                    }
                }

                var oldProcess = Interlocked.Exchange(ref targetProcess, null);
                if (oldProcess != null)
                {
                    oldProcess.Exited -= process_Exited;
                    var deact = Deactivated;
                    if (deact != null) deact(this, EventArgs.Empty);
                    oldProcess.Dispose();

                    checkPositionTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    checkProcessTimer.Change(0, Timeout.Infinite);
                    return;
                }
            }
            catch
            {
                // There are a whole class of UAC and race conditions that we would
                // need to deal with, and would likely do the same thing I am doing
                // right now for them.
            }
            finally
            {
                if (process != null)
                {
                    process.Dispose();
                }
            }

            if (running)
                checkProcessTimer.Change(1000, Timeout.Infinite);
        }
        private void CheckPosition(object state)
        {
            var proc = targetProcess;
            if (proc != null)
            {
                var foreground = NativeMethods.ForegroundWindow;

                // Prevent "this" process from hijacking it.
                WindowSelectionEventArgs windowArgs;
                if (proc.ProcessName != thisProcess)
                {
                    windowArgs = new WindowSelectionEventArgs(proc, NativeMethods.GetWindowInformation(foreground));
                    var selectWindow = SelectWindow;
                    if (selectWindow != null) selectWindow(this, windowArgs);
                    lastArgs = windowArgs;
                }
                else
                {
                    windowArgs = lastArgs;
                }

                if (windowArgs.SelectedWindow == null)
                {
                    checkProcessTimer.Change(0, Timeout.Infinite);
                    return;
                }

                Rect? rect = null;
                try
                {
                    rect = NativeMethods.GetWindowRectangle(windowArgs.SelectedWindow.Handle);
                }
                catch { }

                if (rect != null)
                {
                    if (rect.Value != lastRectangle)
                    {
                        lastRectangle = rect.Value;
                        var tmp = LocationChanged;
                        if (tmp != null) tmp(this, new RectEventArgs(rect.Value));
                    }
                }

                if (running)
                    checkPositionTimer.Change(100, Timeout.Infinite);
            }
            else
            {
                checkProcessTimer.Change(0, Timeout.Infinite);
            }
        }
示例#7
0
        private void CheckPosition(object state)
        {
            var proc = targetProcess;

            if (proc != null)
            {
                var foreground = NativeMethods.ForegroundWindow;

                // Prevent "this" process from hijacking it.
                WindowSelectionEventArgs windowArgs;
                if (proc.ProcessName != thisProcess)
                {
                    windowArgs = new WindowSelectionEventArgs(proc, NativeMethods.GetWindowInformation(foreground));
                    var selectWindow = SelectWindow;
                    if (selectWindow != null)
                    {
                        selectWindow(this, windowArgs);
                    }
                    lastArgs = windowArgs;
                }
                else
                {
                    windowArgs = lastArgs;
                }

                if (windowArgs.SelectedWindow == null)
                {
                    checkProcessTimer.Change(0, Timeout.Infinite);
                    return;
                }

                Rect?rect = null;
                try
                {
                    rect = NativeMethods.GetWindowRectangle(windowArgs.SelectedWindow.Handle);
                }
                catch { }

                if (rect != null)
                {
                    if (rect.Value != lastRectangle)
                    {
                        lastRectangle = rect.Value;
                        var tmp = LocationChanged;
                        if (tmp != null)
                        {
                            tmp(this, new RectEventArgs(rect.Value));
                        }
                    }
                }

                if (running)
                {
                    checkPositionTimer.Change(100, Timeout.Infinite);
                }
            }
            else
            {
                checkProcessTimer.Change(0, Timeout.Infinite);
            }
        }
示例#8
0
        private void CheckProcess(object state)
        {
            lastRectangle = new Rect(0, 0, 0, 0);

            Process process = null;

            try
            {
                var foreground = NativeMethods.ForegroundWindow;
                process = NativeMethods.GetWindowProcess(foreground);
                var info = NativeMethods.GetWindowInformation(foreground);

                var selectWindow = SelectWindow;
                if (process != null && selectWindow != null)
                {
                    var windowArgs = new WindowSelectionEventArgs(process, info);
                    selectWindow(this, windowArgs);

                    if (windowArgs.SelectedWindow != null)
                    {
                        process.Exited += process_Exited;
                        if (!process.HasExited)
                        {
                            targetProcess = process;

                            var act = Activated;
                            if (act != null)
                            {
                                act(this, EventArgs.Empty);
                            }

                            process = null; // Prevent dispose (see finally).
                            checkPositionTimer.Change(0, Timeout.Infinite);
                            return;
                        }
                    }
                }

                var oldProcess = Interlocked.Exchange(ref targetProcess, null);
                if (oldProcess != null)
                {
                    oldProcess.Exited -= process_Exited;
                    var deact = Deactivated;
                    if (deact != null)
                    {
                        deact(this, EventArgs.Empty);
                    }
                    oldProcess.Dispose();

                    checkPositionTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    checkProcessTimer.Change(0, Timeout.Infinite);
                    return;
                }
            }
            catch
            {
                // There are a whole class of UAC and race conditions that we would
                // need to deal with, and would likely do the same thing I am doing
                // right now for them.
            }
            finally
            {
                if (process != null)
                {
                    process.Dispose();
                }
            }

            if (running)
            {
                checkProcessTimer.Change(1000, Timeout.Infinite);
            }
        }