private void selectWindowMenuItem_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            ItemCollection items = selectWindowMenuItem.Items;

            items.Clear();
            ApplicationWindow[] windows = ApplicationWindow.GetApplicationWindows().Where(window => !window.IsIdentical(this)).ToArray();
            for (int index = 0; index < windows.Length; index++)
            {
                ApplicationWindow window     = windows[index];
                Process           process    = Process.GetProcessById(window.ProcessId);
                MenuItem          windowItem = new MenuItem()
                {
                    Header = window.Text,
                    Icon   = new Image()
                    {
                        Source = window.GetIcon(IconSize.Small),
                        Width  = 16,
                        Height = 16,
                    },
                };
                windowItem.Click += (eventSender, eventArgs) => CaptureWindow(window);
                items.Add(windowItem);
            }
            if (items.Count == 0)
            {
                object[] extension = (object[])this.FindResource("noSelectionItem");
                foreach (var item in extension)
                {
                    items.Add(item);
                }
            }
        }
        public static IEnumerable <ApplicationWindow> GetApplicationWindows()
        {
            List <ApplicationWindow> windows  = new List <ApplicationWindow>();
            EnumWindowsCallback      callback = new EnumWindowsCallback(
                (hWnd, lParam) =>
            {
                if (!IsWindowVisible(hWnd) || string.IsNullOrEmpty(GetText(hWnd)))
                {
                    return(true);
                }

                if ((long)GetParent(hWnd) == 0)
                {
                    bool hasOwner = (long)GetWindow(hWnd, GW_OWNER) != 0;
                    uint exStyle  = (uint)GetWindowLongPtr(hWnd, GWL_EXSTYLE);

                    if ((exStyle & WS_EX_TOOLWINDOW) == 0 && !hasOwner)
                    {
                        ApplicationWindow window = new ApplicationWindow(hWnd);
                        windows.Add(window);
                    }
                }

                return(true);
            }
                );

            EnumWindows(callback, IntPtr.Zero);
            return(windows);
        }
Beispiel #3
0
        private void selectWindowsToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripItemCollection items = addWindowsToolStripMenuItem.DropDownItems;

            items.Clear();
            foreach (ApplicationWindow window in ApplicationWindow.GetApplicationWindows())
            {
                if (window.Handle == this.Handle)
                {
                    continue;
                }

                Process process = Process.GetProcessById(window.ProcessId);
                IntPtr  handle  = window.Handle;
                string  title   = window.Text;
                Icon    icon    = window.Icon;

                ToolStripMenuItem windowItem = new ToolStripMenuItem(title);
                windowItem.Click += (eventSender, eventArgs) => CaptureWindow(handle);
                if (icon != null)
                {
                    windowItem.Image = icon.ToBitmap();
                }
                items.Add(windowItem);
            }
            if (items.Count == 0)
            {
                items.Add(NoSelectionItem);
            }
        }
Beispiel #4
0
 public void UnsetWindow()
 {
     if (IsRegistered)
     {
         DesktopWindowManager.Unregister(thumbnail);
         thumbnail = IntPtr.Zero;
     }
     target = null;
 }
        public void CaptureWindow(ApplicationWindow window)
        {
            Thumbnail thumbnail = new Thumbnail();

            SetContextMenu(thumbnail);
            RegisterMouseEvent(thumbnail);
            canvas.Children.Add(thumbnail);
            thumbnail.SetWindow(window);
        }
        private void windowObserver_DoWork(object sender, DoWorkEventArgs e)
        {
            Size sourceSize = DesktopWindowManager.QueryThumbnailSourceSize(thumbnail);

            while (ApplicationWindow.GetApplicationWindows().Any(window => window.Handle == windowHandle))
            {
                Size size = DesktopWindowManager.QueryThumbnailSourceSize(thumbnail);
                if (!sourceSize.Equals(size))
                {
                    sourceSize = size;
                    OnSourceSizeChanged(EventArgs.Empty);
                }
            }
        }
Beispiel #7
0
        public void SetWindow(ApplicationWindow window)
        {
            if (Window.GetWindow(this) == null)
            {
                throw new InvalidOperationException();
            }

            if (window != null && DesktopWindowManager.IsCompositionEnabled)
            {
                target = window;
                Window owner = Window.GetWindow(this);
                if (owner != null)
                {
                    thumbnail = DesktopWindowManager.Register(owner, target);
                    ResetDrawnRegion();
                    UpdateThumbnail();
                }
            }
        }