コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: vsampath/Faceblock
        /// <summary>
        /// Extends the glass frame of a window
        /// </summary>
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!IsDwmCompositionEnabled)
            {
                return(false);
            }

            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            if (hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException("The Window must be shown before extending glass.");
            }

            HwndSource source = HwndSource.FromHwnd(hwnd);

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            source.CompositionTarget.BackgroundColor = Colors.Transparent;

            Interop.Margins margins = new Interop.Margins(margin);
            Interop.DwmExtendFrameIntoClientArea(hwnd, ref margins);
            return(true);
        }
コード例 #2
0
ファイル: GlassHelper.cs プロジェクト: judwhite/CD-Tag
        /// <summary>Extends the glass frame.</summary>
        /// <param name="window">The window.</param>
        /// <param name="margin">The margin.</param>
        /// <returns><c>true</c> if successful; otherwise, <c>false</c>.</returns>
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            Brush oldBackground = window.Background;

            try
            {
                if (!DwmIsCompositionEnabled())
                {
                    return(false);
                }

                IntPtr hwnd = new WindowInteropHelper(window).Handle;
                if (hwnd == IntPtr.Zero)
                {
                    throw new InvalidOperationException("The window must be shown before extending glass.");
                }

                // Set the background to transparent from both the WPF and Win32 perspectives
                window.Background = Brushes.Transparent;
                HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

                MARGINS margins = new MARGINS(margin);
                DwmExtendFrameIntoClientArea(hwnd, ref margins);
                return(true);
            }
            catch (DllNotFoundException)
            {
                window.Background = oldBackground;
                return(false);
            }
        }
コード例 #3
0
ファイル: Window1.xaml.cs プロジェクト: lkruljac/diplomskiV2
        void StartWndProcHandler()
        {
            IntPtr hwnd  = IntPtr.Zero;
            Window myWin = Application.Current.MainWindow;

            try
            {
                hwnd = new WindowInteropHelper(myWin).Handle;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            //Get the Hwnd source
            HwndSource source = HwndSource.FromHwnd(hwnd);

            //Win32 queue sink
            source.AddHook(new HwndSourceHook(WndProc));

            id = new RawStuff.InputDevice(source.Handle);
            NumberOfKeyboards = id.EnumerateDevices();
            id.KeyPressed    += new RawStuff.InputDevice.DeviceEventHandler(_KeyPressed);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: mjdavy/Typing
        /// <summary>
        /// Override for glass look and feel
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSourceInitialized(System.EventArgs e)
        {
            base.OnSourceInitialized(e);


            try
            {
                // This can not be done any earlier than the SourceInitialized event:
                GlassHelper.ExtendGlassFrame(this, new Thickness(-1));

                // Attach a window procedure in order to detect later enabling of desktop composition
                IntPtr hwnd = new WindowInteropHelper(this).Handle;

                var hwndSource = HwndSource.FromHwnd(hwnd);
                if (hwndSource != null)
                {
                    hwndSource.AddHook(new HwndSourceHook(WndProc));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #5
0
        /// <summary>
        /// ウインドウが生成された後の処理で、独自の WndProc を追加する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RibbonWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // I/O ボードのI/O変化はウインドウに対するメッセージという形で通知されるため
            // メッセージをフックするために使用します。
            HwndSource src = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);

            src.AddHook(new HwndSourceHook(WndProc));

            this.DataContext = _viewModel;
            WordModel.Vm     = _viewModel;

            object obj = ModelData;

            VM.PythonConsole = pythonConsole;

            comboBox1.SelectedIndex = 0;

            //ステータス取得用のタイマーイベントを設定
            _timer          = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Normal, this.Dispatcher);
            _timer.Interval = TimeSpan.FromSeconds(0.1);
            _timer.Tick    += new EventHandler(TimerFunc);
//タイマーの開始はスクリプトのロードが完了してからにする
//			_timer.Start();
        }
コード例 #6
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="hWnd">需要捕获手柄消息的窗口</param>
        /// <param name="joystickId">要捕获的手柄Id</param>
        public bool Register(IntPtr hWnd, int joystickId)
        {
            bool flag   = false;
            int  result = 0;

            API.JOYCAPS caps = new API.JOYCAPS();
            if (API.joyGetNumDevs() != 0)
            {
                //拥有手柄.则判断手柄状态
                result = API.joyGetDevCaps(joystickId, ref caps, Marshal.SizeOf(typeof(API.JOYCAPS)));
                if (result == API.JOYERR_NOERROR)
                {
                    //手柄处于正常状态
                    flag = true;
                }
            }

            if (flag)
            {
                //注册消息
                if (!this.IsRegister)
                {
                    _HWndSource = HwndSource.FromHwnd(hWnd);
                    _HWndSource.AddHook(WndProc);
                    //Application.AddMessageFilter(this);
                }
                this.IsRegister = true;

                result = API.joySetCapture(hWnd, joystickId, caps.wPeriodMin * 2, false);
                if (result != API.JOYERR_NOERROR)
                {
                    flag = false;
                }
            }
            return(flag);
        }
コード例 #7
0
ファイル: WindowHelper.cs プロジェクト: hamerstandr/CodeRuner
        private static void TransformToPixels(this Visual visual,
                                              double unitX,
                                              double unitY,
                                              out int pixelX,
                                              out int pixelY)
        {
            Matrix matrix;
            var    source = PresentationSource.FromVisual(visual);

            if (source != null)
            {
                matrix = source.CompositionTarget.TransformToDevice;
            }
            else
            {
                using (var src = new HwndSource(new HwndSourceParameters()))
                {
                    matrix = src.CompositionTarget.TransformToDevice;
                }
            }

            pixelX = (int)Math.Round(matrix.M11 * unitX);
            pixelY = (int)Math.Round(matrix.M22 * unitY);
        }
コード例 #8
0
        // ************************************************************************
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            // Method 1

            //IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
            //HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
            //if (mainWindowSrc != null)
            //{
            //	mainWindowSrc.AddHook(WndProc);
            //}

            // Method 2
            HwndSource source = PresentationSource.FromVisual(this) as HwndSource;

            source.AddHook(WndProc);

            _hotKeyHandler = new HotKeyHandeler(this);
            _hotKeyHandler.HotKeyPressed += _hotKeyHandler_HotKeyPressed;
            //	_hotKeyHandler.RegisterHotKey(0, Key.NumPad0);

            this.Visibility = Visibility.Hidden;
        }
コード例 #9
0
        /// <summary> 添加监视消息 </summary>
        void win_SourceInitialized(object sender, EventArgs e)
        {
            HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;

            hwndSource?.AddHook(new HwndSourceHook(clipMonitor.WndProc));
        }
コード例 #10
0
 private void DesktopToolbar_SourceInitialized(object sender, EventArgs e)
 {
     helper = new WindowInteropHelper(this);
     HwndSource.FromHwnd(helper.Handle).AddHook(new HwndSourceHook(WndProc));
     Shell.HideWindowFromTasks(helper.Handle);
 }
コード例 #11
0
ファイル: WindowInfo.cs プロジェクト: gkjolin/xenko
 internal static Window FromHwnd(IntPtr hwnd)
 {
     return(hwnd != IntPtr.Zero ? HwndSource.FromHwnd(hwnd)?.RootVisual as Window : null);
 }
コード例 #12
0
ファイル: KeyTipAdorner.cs プロジェクト: team55/Fluent.Ribbon
        /// <summary>
        /// Attaches this adorner to the adorned element
        /// </summary>
        public void Attach()
        {
            if (this.attached)
            {
                return;
            }

            this.oneOfAssociatedElements.UpdateLayout();

            this.Log("Attach begin {0}", this.Visibility);

            if (!this.oneOfAssociatedElements.IsLoaded)
            {
                // Delay attaching
                this.Log("Delaying attach");
                this.oneOfAssociatedElements.Loaded += this.OnDelayAttach;
                return;
            }

            this.adornerLayer = GetAdornerLayer(this.oneOfAssociatedElements);

            if (this.adornerLayer == null)
            {
                this.Log("No adorner layer found");
                return;
            }

            // Focus current adorned element
            // Keyboard.Focus(adornedElement);
            this.focusedElement = Keyboard.FocusedElement;

            if (this.focusedElement != null)
            {
                this.Log("Focus Attached to {0}", this.focusedElement);
                this.focusedElement.LostKeyboardFocus += this.OnFocusLost;
                this.focusedElement.PreviewKeyDown    += this.OnPreviewKeyDown;
                this.focusedElement.PreviewTextInput  += this.OnFocusedElementPreviewTextInput;
            }
            else
            {
                this.Log("[!] Focus Setup Failed");
            }

            GetTopLevelElement(this.oneOfAssociatedElements).PreviewMouseDown += this.OnInputActionOccured;

            // Clears previous user input
            this.enteredKeys = "";
            this.FilterKeyTips();

            // Show this adorner
            this.adornerLayer.Add(this);

            // Hookup window activation
            this.attachedHwndSource = ((HwndSource)PresentationSource.FromVisual(this.oneOfAssociatedElements));
            if (this.attachedHwndSource != null)
            {
                this.attachedHwndSource.AddHook(this.WindowProc);
            }

            // Start timer to track focus changing
            if (this.timerFocusTracking == null)
            {
                this.timerFocusTracking = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher.CurrentDispatcher)
                {
                    Interval = TimeSpan.FromMilliseconds(50)
                };
                this.timerFocusTracking.Tick += this.OnTimerFocusTrackingTick;
            }

            this.timerFocusTracking.Start();

            this.attached = true;

            this.Log("Attach end");
        }
コード例 #13
0
        public WebBrowserOverlayWF(FrameworkElement placementTarget)
        {
            _placementTarget = placementTarget;
            Window owner = Window.GetWindow(placementTarget);

            Debug.Assert(owner != null);
            _owner = owner;

            _form                 = new Form();
            _form.Opacity         = owner.Opacity;
            _form.ShowInTaskbar   = false;
            _form.FormBorderStyle = FormBorderStyle.None;
            _wb.Dock              = DockStyle.Fill;
            _form.Controls.Add(_wb);

            // _form.TransparencyKey =   System.Drawing.Color.FromArgb(255,255,255);
            //_form.Opacity = 0.8;

            //owner.SizeChanged += delegate { OnSizeLocationChanged(); };
            owner.LocationChanged        += delegate { OnSizeLocationChanged(); };
            _placementTarget.SizeChanged += delegate { OnSizeLocationChanged(); };

            if (owner.IsVisible)
            {
                InitialShow();
            }
            else
            {
                owner.SourceInitialized += delegate {
                    InitialShow();
                }
            };

            DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(UIElement.OpacityProperty, typeof(Window));

            dpd.AddValueChanged(owner, delegate { _form.Opacity = _owner.Opacity; });

            _form.FormClosing += delegate { _owner.Close(); };
        }

        void InitialShow()
        {
            NativeWindow owner = new NativeWindow();

            owner.AssignHandle(((HwndSource)HwndSource.FromVisual(_owner)).Handle);
            _form.Show(owner);
            owner.ReleaseHandle();
        }

        DispatcherOperation _repositionCallback;

        void OnSizeLocationChanged()
        {
            // To reduce flicker when transparency is applied without DWM composition,
            // do resizing at lower priority.


            if (_repositionCallback == null)
            {
                _repositionCallback = _owner.Dispatcher.BeginInvoke(
                    new Action(() => {
                    Reposition();
                }),
                    DispatcherPriority.Input
                    );
            }
        }

        void Reposition()
        {
            _repositionCallback = null;

            Point             offset     = _placementTarget.TranslatePoint(new Point(), _owner);
            Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
            CompositionTarget ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(_form.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            //_form.SetBounds(screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y);
            //_form.Update();
        }
    };
}
コード例 #14
0
 public static bool ReleaseContext(HwndSource source, IntPtr hIMC)
 {
     return(source != null && hIMC != IntPtr.Zero && ImmReleaseContext(source.Handle, hIMC));
 }
コード例 #15
0
 protected override void OnSourceInitialized(EventArgs e)
 {
     base.OnSourceInitialized(e);
     handle = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
     handle?.AddHook(WndProc);
 }
コード例 #16
0
        public static void RemoveHook(this Window window, HwndSourceHook hook)
        {
            var source = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);

            source.RemoveHook(hook);
        }
コード例 #17
0
        private void ShowChild()
        {
            _childWnd = new T();
            try
            {
                _childWnd.ParentDlg = this;
            }
            catch
            {
                return;
            }

            RECT dialogWindowRect = new RECT();
            RECT dialogClientRect = new RECT();

            Size size = new Size(dialogWindowRect.Width, dialogWindowRect.Height);

            NativeMethods.GetClientRect(new HandleRef(this, _hwndFileDialog), ref dialogClientRect);
            NativeMethods.GetWindowRect(new HandleRef(this, _hwndFileDialog), ref dialogWindowRect);
            int dy = (int)(dialogWindowRect.Height - dialogClientRect.Height);
            int dx = (int)(dialogWindowRect.Width - dialogClientRect.Width);

            size = new Size(dialogWindowRect.Width, dialogWindowRect.Height);

            if (_childWnd is Window)
            {
                Window wnd = _childWnd as Window;
                wnd.WindowStyle   = WindowStyle.None;
                wnd.ResizeMode    = ResizeMode.NoResize;//will fix the child window!!
                wnd.ShowInTaskbar = false;
                //won't flash on screen
                wnd.WindowStartupLocation = WindowStartupLocation.Manual;
                wnd.Left = -10000;
                wnd.Top  = -10000;
                wnd.SourceInitialized += delegate(object sender, EventArgs e)
                {
                    try
                    {
                        _source = System.Windows.PresentationSource.FromVisual(_childWnd as Window) as HwndSource;
                        _source.AddHook(EmbededWndProc);
                        _childWnd.Source = _source;
                    }
                    catch
                    {
                    }
                };

                wnd.Show();

                long styles = (long)NativeMethods.GetWindowLongPtr(new HandleRef(_childWnd, _source.Handle), GWL.GWL_STYLE);
                if (IntPtr.Size == 4)
                {
                    styles |= System.Convert.ToInt64(NativeMethods.WindowStyles.WS_CHILD);
                    styles ^= System.Convert.ToInt64(NativeMethods.WindowStyles.WS_SYSMENU);
                }
                else
                {
                    styles |= (long)NativeMethods.WindowStyles.WS_CHILD;
                    styles ^= (long)NativeMethods.WindowStyles.WS_SYSMENU;
                }
                NativeMethods.CriticalSetWindowLong(new HandleRef(this, _source.Handle), (int)GWL.GWL_STYLE, new IntPtr(styles));

                // Everything is ready, now lets change the parent
                NativeMethods.SetParent(new HandleRef(_childWnd, _source.Handle), new HandleRef(this, _hwndFileDialog));
            }
            else
            {// To do: what if the child is not a Window
                //see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b2cff333-cbd9-4742-beba-ba19a15eeaee
                ContentControl       ctrl       = _childWnd as ContentControl;
                HwndSourceParameters parameters = new HwndSourceParameters("WPFDlgControl", (int)ctrl.Width, (int)ctrl.Height);
                parameters.WindowStyle = (int)NativeMethods.WindowStyles.WS_VISIBLE | (int)NativeMethods.WindowStyles.WS_CHILD;
                parameters.SetPosition((int)_OriginalRect.Width, (int)_OriginalRect.Height);
                parameters.ParentWindow = _hwndFileDialog;
                parameters.AdjustSizingForNonClientArea = false;
                switch (this.FileDlgStartLocation)
                {
                case AddonWindowLocation.Right:
                    parameters.PositionX = (int)(_OriginalRect.Width - dx / 2);
                    parameters.PositionY = 0;
                    if (ctrl.Height < _OriginalRect.Height - dy)
                    {
                        ctrl.Height = parameters.Height = (int)_OriginalRect.Height - dy;
                    }
                    break;

                case AddonWindowLocation.Bottom:
                    parameters.PositionX = 0;
                    parameters.PositionY = (int)(_OriginalRect.Height - dy + dx / 2);
                    if (ctrl.Width < _OriginalRect.Width - dx)
                    {
                        ctrl.Width = parameters.Width = (int)_OriginalRect.Width - dx;
                    }
                    break;

                case AddonWindowLocation.BottomRight:
                    parameters.PositionX = (int)_OriginalRect.Width - dx / 2;
                    parameters.PositionY = (int)(_OriginalRect.Height - dy + dx / 2);
                    break;
                }

                _source = new HwndSource(parameters);
                _source.CompositionTarget.BackgroundColor = System.Windows.Media.Colors.LightGray;
                _source.RootVisual = _childWnd as System.Windows.Media.Visual;
                _source.AddHook(new HwndSourceHook(EmbededCtrlProc));
            }
            switch (this.FileDlgStartLocation)
            {
            case AddonWindowLocation.Right:
                size.Width  = (int)(_OriginalRect.Width + _childWnd.Width);
                size.Height = _OriginalRect.Height;
                break;

            case AddonWindowLocation.Bottom:
                size.Width  = _OriginalRect.Width;
                size.Height = _OriginalRect.Height + _childWnd.Height;
                break;

            case AddonWindowLocation.BottomRight:
                size.Height = _OriginalRect.Height + _childWnd.Height;
                size.Width  = _OriginalRect.Width + _childWnd.Width;
                break;
            }
            NativeMethods.SetWindowPos(new HandleRef(this, _hwndFileDialog), new HandleRef(this, (IntPtr)NativeMethods.ZOrderPos.HWND_BOTTOM),
                                       0, 0, (int)size.Width, (int)size.Height, NativeMethods.SetWindowPosFlags.SWP_NOZORDER);
        }
コード例 #18
0
 private static IntPtr GetHandle(HwndSource hwnd)
 {
     // add hook to the popup's window
     return(hwnd != null ? hwnd.Handle : IntPtr.Zero);
 }
コード例 #19
0
ファイル: Receiver.xaml.cs プロジェクト: Zivaka/VirtualPC_WPF
        private void Window_SourceInitialized(object sender, EventArgs e)
        {
            HwndSource source = PresentationSource.FromVisual(this) as HwndSource;

            source?.AddHook(WndProc);
        }
コード例 #20
0
 public RawInputListener(Window window)
 {
     _hwnd = new WindowInteropHelper(window).Handle;
     HwndSource.FromHwnd(_hwnd).AddHook(WndProc);
 }
コード例 #21
0
 public void PowerManagementRegistration(Window window, ISystemState systemState)
 {
     SystemState = systemState;
     PowerManager.RegisterMonitorStatusChange(window);
     HwndSource.FromHwnd(new WindowInteropHelper(window).Handle).AddHook(WndProc);
 }
コード例 #22
0
        public void Load(IntPtr mainWindowHandle, Window mainWindow, Window settingsWindow, Grid mainGrid, DockPanel outputDock, DockPanel inputDock, Canvas clickThroughButton, Canvas autoShowButton, Canvas autoScrollButton, Canvas settingsButton, Canvas closeButton, Canvas autoShowButtonBackground, Canvas autoScrollButtonBackground, Canvas settingsButtonBackground, Canvas closeButtonBackground, Canvas moveButton, Canvas minimiseButton, Canvas minimiseButtonBackground, RichTextBox output, TextBox input)
        {
            var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
            var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);
            var h            = HwndSource.FromVisual(mainWindow) as HwndSource;

            MainWindowHandle    = mainWindowHandle;
            BackgroundColor     = ((SolidColorBrush)mainWindow.Resources["BaseColour"]).Color;
            TextBackgroundColor = ((SolidColorBrush)mainWindow.Resources["SubsectionColour"]).Color;
            TextColor           = ((SolidColorBrush)mainWindow.Resources["TextColour"]).Color;
            h.AddHook(WndProc);
            dpiX                          = (double)96 / (int)dpiXProperty.GetValue(null, null);
            dpiY                          = (double)96 / (int)dpiYProperty.GetValue(null, null);
            SettingsWindow                = settingsWindow;
            MainWindow                    = mainWindow;
            MainGrid                      = mainGrid;
            OutputDock                    = outputDock;
            InputDock                     = inputDock;
            ClickThroughButton            = clickThroughButton;
            AutoShowButton                = autoShowButton;
            AutoScrollButton              = autoScrollButton;
            SettingsButton                = settingsButton;
            CloseButton                   = closeButton;
            MinimiseButton                = minimiseButton;
            MoveButton                    = moveButton;
            AutoShowButtonBackground      = autoShowButtonBackground;
            AutoScrollButtonBackground    = autoScrollButtonBackground;
            SettingsButtonBackground      = settingsButtonBackground;
            CloseButtonBackground         = closeButtonBackground;
            MinimiseButtonBackground      = minimiseButtonBackground;
            Output                        = output;
            Input                         = input;
            ClickThroughButton.Background = ImageResources.ClickThroughDisabled;
            AutoShowButton.Background     = ImageResources.AutoShowDisabled;
            AutoScrollButton.Background   = ImageResources.AutoScroll;
            CloseButton.Background        = ImageResources.Close;
            SettingsButton.Background     = ImageResources.Settings;
            MinimiseButton.Background     = ImageResources.Minimise;
            DisableAutoShowHighlight();
            DisableAutoScrollHighlight();
            DisableSettingsHighlight();
            DisableCloseHighlight();
            DisableMinimiseHighlight();
            ApplySettings();
            ApplyTranslation(Settings.Language);
            MainWindow.Closing                        += WindowClosing;
            MainWindow.Closed                         += WindowClosed;
            MainWindow.SizeChanged                    += MainWindow_SizeChanged;
            Input.KeyDown                             += Input_KeyDown;
            Input.PreviewKeyDown                      += Input_PreviewKeyDown;
            SettingsWindow.Deactivated                += SettingsWindow_Deactivate;
            AutoShowButton.MouseEnter                 += AutoShowButton_MouseEnter;
            AutoShowButton.MouseLeave                 += AutoShowButton_MouseLeave;
            AutoScrollButton.MouseEnter               += AutoScrollButton_MouseEnter;
            AutoScrollButton.MouseLeave               += AutoScrollButton_MouseLeave;
            SettingsButton.MouseEnter                 += SettingsButton_MouseEnter;
            SettingsButton.MouseLeave                 += SettingsButton_MouseLeave;
            CloseButton.MouseEnter                    += CloseButton_MouseEnter;
            CloseButton.MouseLeave                    += CloseButton_MouseLeave;
            MinimiseButton.MouseEnter                 += MinimiseButton_MouseEnter;
            MinimiseButton.MouseLeave                 += MinimiseButton_MouseLeave;
            MoveButton.MouseDown                      += MoveStart;
            Settings.AdditionalInfo.OnChanged         += AdditionalInfoSettingChanged;
            Settings.PartialTransparency.OnChanged    += PartialOpacitySettingChanged;
            Settings.ColourChat.OnChanged             += ColourChatMessagesSettingChanged;
            Settings.ClickthroughKeyEnabled.OnChanged += EnableClickthroughKeySettingChanged;
            Settings.ClickthroughKey.OnChanged        += ClickthroughKeySettingChanged;
            Settings.OCRKey.OnChanged                 += OCRKeySettingChanged;
            Settings.OCRKeyEnabled.OnChanged          += EnableOCRKeySettingChanged;
            Settings.OnLanguageChanged                += LanguageSettingChanged;
            Settings.AutoShow.OnChanged               += AutoShowSettingChanged;
            ConfigureMouseClickEvent(AutoShowButton, AutoShowButton_Click);
            ConfigureMouseClickEvent(AutoScrollButton, AutoScrollButton_Click);
            ConfigureMouseClickEvent(SettingsButton, SettingsButton_Click);
            ConfigureMouseClickEvent(CloseButton, CloseButton_Click);
            ConfigureMouseClickEvent(MinimiseButton, MinimiseButton_Click);
            Wait = 4;
            //MainWindow.Hide();
            Translate.Start(this);
            timer = new Timer(MainWindow, 16, OnTick);
            timer.Start();
            Settings.FirstTimeStartup.Value = false;
        }
コード例 #23
0
 private HotKeyHandler(IntPtr hWnd)
 {
     this.hWnd = hWnd;
     source    = HwndSource.FromHwnd(hWnd);
 }
コード例 #24
0
ファイル: ClipboardMonitor.cs プロジェクト: havardhu/clippy
 public static void Initialize(Visual visual)
 {
     _source = PresentationSource.FromVisual(visual) as HwndSource;
     _source.AddHook(WndProc);
     _nextClipboardViewer = SetClipboardViewer(_source.Handle);
 }
コード例 #25
0
        private void Window_SourceInitialized(object sender, EventArgs ea)
        {
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual((Window)sender);

            hwndSource.AddHook(DragHook); _aspectRatio = Width / Height;
        }
コード例 #26
0
        private void RestorePreviousFocus()
        {
            // Only restore focus if focus is still within the menu.  If
            // focus has already been moved outside of the menu, then
            // we don't want to disturb it.
            if (IsKeyboardFocusWithin)
            {
                // Only restore WPF focus if the HWND with focus is an
                // HwndSource.  This enables child HWNDs, other top-level
                // non-WPF HWNDs, or even child HWNDs of other WPF top-level
                // windows to retain focus when menus are dismissed.
                IntPtr     hwndWithFocus       = MS.Win32.UnsafeNativeMethods.GetFocus();
                HwndSource hwndSourceWithFocus = hwndWithFocus != IntPtr.Zero ? HwndSource.CriticalFromHwnd(hwndWithFocus) : null;
                if (hwndSourceWithFocus != null)
                {
                    // We restore focus by setting focus to the parent's focus
                    // scope.  This may not seem correct, because it presumes
                    // the focus came from the logical-focus element of the
                    // parent scope.  In fact, it could have come from any
                    // number of places.  However, we have not figured out a
                    // better solution for restoring focus across scenarios
                    // such as:
                    //
                    // 1) A context menu of a menu item.
                    // 2) Two menus side-by-side
                    // 3) A menu and a toolbar side-by-side
                    //
                    // Simply remembering the last element with focus and
                    // restoring focus to it does not work.  For example,
                    // two menus side-by-side will end up remembering each
                    // other, and you can get stuck in an infinite loop.
                    //
                    // Restoring focus through the parent's focus scope will
                    // not directly work if you open one window's menu from
                    // another window. Visual Studio, as an example, will
                    // intercept the focus change events and forward
                    // appropriately for the scenario of restoring focus to
                    // an element in a different top-level window.

                    // DependencyObject parent = Parent;
                    // if (parent == null)
                    // {
                    // If there is no logical parent, use the visual parent.
                    //     parent = VisualTreeHelper.GetParent(this);
                    // }

                    // if (parent != null)
                    // {
                    //     IInputElement parentScope = FocusManager.GetFocusScope(parent) as IInputElement;
                    //     if (parentScope != null)
                    //     {
                    //         Keyboard.Focus(parentScope);
                    //     }
                    // }

                    // Unfortunately setting focus to the parent focusscope tripped up VS in the scenario where
                    // Menus are contained within ToolBars. In this case when the Menu is dismissed they want
                    // focus to be restored to the element in the main window that previously had focus. However
                    // since ToolBar is  the parent focusscope for the Menu we end up restoring focus to its
                    // focusedelment. It is also noted that this implementation is a behavioral change from .Net 3.5.
                    // Hence we are putting back the old behavior which is to set Keyboard.Focus to null which will
                    // delegate focus through the main window to its focusedelement.

                    Keyboard.Focus(null);
                }
                else
                {
                    // In the case where Win32 focus is not on a WPF
                    // HwndSource, we just clear WPF focus completely.
                    //
                    // Note that calling Focus(null) will set focus to the root
                    // element of the active source, which is not what we want.
                    Keyboard.ClearFocus();
                }
            }
        }
コード例 #27
0
ファイル: WmManager.cs プロジェクト: radtek/WinEventListener
 public WmManager(int wmMessage, HwndSource presentationSource)
 {
     _wmMessage         = wmMessage;
     PresentationSource = presentationSource;
     InstallHooksAndRegister();
 }
コード例 #28
0
 /// <summary>
 ///     Create an observable for the specified HwndSource
 /// </summary>
 public static IObservable <WindowMessageInfo> WinProcMessages(this HwndSource hWndSource)
 {
     return(WinProcMessages <Unit>(null, hWndSource));
 }
コード例 #29
0
 public static void RemoveHotkey(Window parentWindow)
 {
     HwndSource.RemoveHook(HwndHook);
     HwndSource = null;
     UnregisterHotKey(parentWindow);
 }
コード例 #30
0
        /// <summary>
        /// Create an observable for the specified window or HwndSource
        /// </summary>
        /// <param name="window">Window</param>
        /// <param name="hWndSource">HwndSource</param>
        /// <param name="before">Func which does something as soon as the observable is created</param>
        /// <param name="disposeAction">Action which disposes something when the observable is disposed</param>
        /// <returns>IObservable</returns>
        internal static IObservable <WindowMessageInfo> WinProcMessages <TState>(Window window, HwndSource hWndSource, Func <IntPtr, TState> before = null, Action <TState> disposeAction = null)
        {
            if (window == null && hWndSource == null)
            {
                throw new NotSupportedException("One of Window or HwndSource must be supplied");
            }

            return(Observable.Create <WindowMessageInfo>(observer =>
            {
                // This handles the message, and generates the observable OnNext
                IntPtr WindowMessageHandler(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
                {
                    observer.OnNext(WindowMessageInfo.Create(hWnd, msg, wParam, lParam));
                    // ReSharper disable once AccessToDisposedClosure
                    if (hWndSource.IsDisposed)
                    {
                        observer.OnCompleted();
                    }
                    return IntPtr.Zero;
                }

                TState state = default;

                void HwndSourceDisposedHandle(object sender, EventArgs e)
                {
                    observer.OnCompleted();
                }

                void RegisterHwndSource()
                {
                    if (before != null)
                    {
                        state = before(hWndSource.Handle);
                    }
                    hWndSource.Disposed += HwndSourceDisposedHandle;
                    hWndSource.AddHook(WindowMessageHandler);
                }

                if (window != null)
                {
                    hWndSource = window.ToHwndSource();
                }
                if (hWndSource != null)
                {
                    RegisterHwndSource();
                }
                else if (window != null)
                {
                    // No, try to get it later
                    window.SourceInitialized += (sender, args) =>
                    {
                        hWndSource = window.ToHwndSource();
                        RegisterHwndSource();
                        // Simulate the WM_NCCREATE
                        observer.OnNext(WindowMessageInfo.Create(hWndSource.Handle, (int)WindowsMessages.WM_NCCREATE, IntPtr.Zero, IntPtr.Zero));
                    };
                }

                return Disposable.Create(() =>
                {
                    disposeAction?.Invoke(state);
                    hWndSource.Disposed -= HwndSourceDisposedHandle;
                    hWndSource.RemoveHook(WindowMessageHandler);
                    hWndSource.Dispose();
                });
            })
                   // Make sure there is always a value produced when connecting
                   .Publish()
                   .RefCount());
        }