public static IDisposable Subscribe(this IObserver <WinEventInfo> observer, WinEvents winEventStart, WinEvents winEventEnd, ObjectIdentifiers objectIdentifiers) { return(WinEventHook .Create(winEventStart, winEventEnd) .Where(x => x.IdChild == CHILDID_SELF && x.ObjectIdentifier == objectIdentifiers) .Subscribe(observer)); }
/// <summary> /// The constructor /// </summary> /// <param name="pipConfiguration">IPipConfiguration</param> /// <param name="locationPool">LocationPool used to find a location</param> /// <param name="hWnd">IntPtr with the hWnd to mirror</param> /// <param name="uiSynchronizationContext">SynchronizationContext used to make it possible to modify the UI</param> public ThumbnailForm(IPipConfiguration pipConfiguration, LocationPool locationPool, IntPtr hWnd, SynchronizationContext uiSynchronizationContext) { _thumbnailRect = locationPool.Pool(); SetStyle(ControlStyles.SupportsTransparentBackColor, true); _pipConfiguration = pipConfiguration; _locationPool = locationPool; // Make sure that changes to the settings are applied _configurationMonitor = _pipConfiguration.OnPropertyChanged() .Where(args => PropertiesToMonitor.Contains(args.PropertyName)) .Throttle(TimeSpan.FromMilliseconds(200)) .SubscribeOn(uiSynchronizationContext) .ObserveOn(uiSynchronizationContext) .Subscribe(args => UpdateThumbnail()); _hWnd = hWnd; // Make sure the PIP closes when the source closes _windowCloseMonitor = WinEventHook.Create(WinEvents.EVENT_OBJECT_DESTROY) .SubscribeOn(uiSynchronizationContext) .ObserveOn(uiSynchronizationContext) .Subscribe(info => { if (info.Handle == _hWnd) { Close(); } }); // Make sure the thumbnail changes when the window changes _windowSizeChangeMonitor = WinEventHook.Create(WinEvents.EVENT_OBJECT_LOCATIONCHANGE) .SubscribeOn(uiSynchronizationContext) .ObserveOn(uiSynchronizationContext) .Subscribe(info => { if (info.Handle == _hWnd) { UpdateThumbnail(); } }); Location = _thumbnailRect.Location; Size = _thumbnailRect.Size; StartPosition = FormStartPosition.Manual; TopMost = true; Text = "PIP"; FormBorderStyle = FormBorderStyle.None; BackColor = Color.Gray; Enabled = false; ShowInTaskbar = false; }