public HorizontalMouseScrollHelper(ScrollViewer scrollviewer, DependencyObject d)
 {
     scrollViewer = scrollviewer;
     source = (HwndSource)PresentationSource.FromDependencyObject(d);
     if (source != null)
         source.AddHook(WindowProc);
 }
Пример #2
1
 public NotifyIcon(Window parent, System.Drawing.Icon icon)
 {
     _data = new NotifyIconData();
     _data.cbSize = Marshal.SizeOf(typeof(NotifyIconData));
     _data.uID = _id++;
     _data.uFlags = 0x8 | 0x2 | 0x1;
     _data.dwState = 0x0;
     _data.hIcon = icon.Handle;
     _data.hWnd = new WindowInteropHelper(parent).Handle;
     _data.uCallbackMessage = 0x5700;
     _src = HwndSource.FromHwnd(_data.hWnd);
     _src.AddHook(new HwndSourceHook(WndProc));
     Shell_NotifyIcon(0x0, ref _data);
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HotKeyManager"/> class.
        /// </summary>
        public HotKeyManager()
        {
            _windowHandleSource = new HwndSource(new HwndSourceParameters());
            _windowHandleSource.AddHook(messagesHandler);

            _registered = new Dictionary<HotKey, int>();
        }
 protected void OnLoaded(object sender, EventArgs e)
 {
     WindowInteropHelper helper = new WindowInteropHelper(this);
     _hwndSource = HwndSource.FromHwnd(helper.Handle);
     _wndProcHandler = new HwndSourceHook(HookHandler);
     _hwndSource.AddHook(_wndProcHandler);
 }
Пример #5
0
 public HotkeyManager(Window window)
 {
     source = (HwndSource)PresentationSource.FromVisual(window);
     hook = new HwndSourceHook(WndProc);
     source.AddHook(hook);
     ids = new List<int>();
 }
 private void StartListeningToClipboard()
 {
     var lWindowInteropHelper = new WindowInteropHelper(this);
     _HWndSource = HwndSource.FromHwnd(lWindowInteropHelper.Handle);
     _HWndSource.AddHook(WinProc);
     _HWndNextViewer = SetClipboardViewer(_HWndSource.Handle); // set this window as a viewer
 } //
Пример #7
0
    private void ShadowedWindow_OnLoaded(object sender, RoutedEventArgs e)
    {
      hwndSource = PresentationSource.FromVisual((Visual) sender) as HwndSource;

      if (hwndSource != null)
        hwndSource.AddHook(WndProc);
    }
Пример #8
0
		private void Start()
		{
			if (hwndSource != null)
				return;


			var window = Application.Current.Windows[0];
			Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
			{

				if (!window.IsInitialized)
					window.SourceInitialized += (sender, args) =>
					{
						hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
						hwndSource.AddHook(WndProc);
					};
				else
				{
					hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
					hwndSource.AddHook(WndProc);
				}
			}));



		}
Пример #9
0
        private void InitCBViewer()
        {
            WindowInteropHelper wih = new WindowInteropHelper(this);
            hWndSource = HwndSource.FromHwnd(wih.Handle);

            hWndSource.AddHook(this.WndProc);   // start processing window messages
            hWndNextViewer = Win32.SetClipboardViewer(hWndSource.Handle);   // set this window as a viewer
        }
Пример #10
0
 protected override void OnSourceInitialized(EventArgs e)
 {
     base.OnSourceInitialized(e);
     var helper = new WindowInteropHelper(this);
     _source = HwndSource.FromHwnd(helper.Handle);
     _source.AddHook(HwndHook);
     RegisterHotKey();
 }
 private void AddHook(Visual window)
 {
     if (_hwndSource != null) return;
     _hwndSource = PresentationSource.FromVisual(window) as HwndSource;
     if (_hwndSource != null)
     {
         _hwndSource.AddHook(HwndSourceHook);
     }
 }
Пример #12
0
        public HotKey(HwndSource hwndSource)
        {
            hook = WndProc;
            this.hwndSource = hwndSource;
            hwndSource.AddHook(hook);

            var rand = new Random((int)DateTime.Now.Ticks);
            id = rand.Next();
        }
Пример #13
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            hWndSrc = PresentationSource.FromVisual(this) as HwndSource;
            DataContext = mainViewModel = new MainViewModel(this.Dispatcher, hWndSrc.Handle);
            hWndSrc.AddHook(mainViewModel.ApiInstance.WndProc);
            mainViewModel.ConnectToHost();
        }
Пример #14
0
        private void RegisterHotKey()
        {
            IntPtr hwnd = new WindowInteropHelper(this).Handle;

            //获得消息源
            System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(hwnd);

            source.AddHook(HotKeyHook);
        }
Пример #15
0
        public WindowResizer(Window window)
        {
            activeWin = window as Window;

            activeWin.SourceInitialized += (sender, e) =>
            {
                hwndSource = PresentationSource.FromVisual(sender as Visual) as HwndSource;
                hwndSource.AddHook(new HwndSourceHook(WndProc));
            };
        }
Пример #16
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            _windowHandle = new WindowInteropHelper(this).Handle;
            _source = HwndSource.FromHwnd(_windowHandle);
            _source.AddHook(HwndHook);

            RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_SPACE); //CTRL + SPACE
        }
Пример #17
0
 /// <summary>
 /// Setup wndproc handling so we can receive window messages (Win32 stuff)
 /// </summary>
 /// <exception cref="Exception">Failed to acquire window handle</exception>
 public void Setup(Window window)
 {
     var windowHelper = new WindowInteropHelper(window);
     windowHelper.EnsureHandle();
     _hwndSource = HwndSource.FromHwnd(windowHelper.Handle);
     if (_hwndSource == null) {
         throw new Exception("Failed to acquire window handle");
     }
     _hwndSource.AddHook(HandleMessages);
 }
Пример #18
0
        public static bool Start(Action<ClipboardSnapshot> onChanged, HwndSource source)
        {
            OnChanged = onChanged;

            source.AddHook(WndProc);
            WindowHandle = source.Handle;

            NextClipboardViewer = NativeMethods.SetClipboardViewer(WindowHandle);
            return NextClipboardViewer != IntPtr.Zero;
        }
Пример #19
0
        //=============================================================================
        void OnSourceInitialized(object sender, EventArgs e)
        {
            System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(new System.Windows.Interop.WindowInteropHelper(this).Handle);
            source.AddHook(new System.Windows.Interop.HwndSourceHook(WndProc));

            //
            m_WndHandle = new WindowInteropHelper(this).Handle;
            WindowsUtils.DisableMaximizeButton(m_WndHandle);
            WindowsUtils.EnableMinimizeButton(m_WndHandle);
        }
 private void AddHook(Window window)
 {
     if (_hwndSource == null)
     {
         _hwndSource = PresentationSource.FromVisual(window) as HwndSource;
         if (_hwndSource != null)
         {
             _hwndSource.AddHook(new HwndSourceHook(hwndSourceHook));
         }
     }
 }
Пример #21
0
        public HotkeyHook(Window window, MainWindowViewModel viewModel)
        {
            _viewModel = viewModel;
            _windowHandle = new WindowInteropHelper(window).Handle;
            _source = HwndSource.FromHwnd(_windowHandle);
            _source.AddHook(HwndHook);

            RegisterHotKey(_windowHandle, KEY_X.GetHashCode(), MOD_ALT, KEY_X);
            RegisterHotKey(_windowHandle, KEY_Z.GetHashCode(), MOD_ALT, KEY_Z);
            RegisterHotKey(_windowHandle, KEY_C.GetHashCode(), MOD_ALT, KEY_C);
            RegisterHotKey(_windowHandle, KEY_S.GetHashCode(), MOD_ALT, KEY_S);
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkypeConnector"/> class.
        /// </summary>
        public SkypeConnector()
        {
            // Create dummy handle source to catch Windows API messages.
            _windowHandleSource = new HwndSource(new HwndSourceParameters());

            // Hook messages to window.
            _windowHandleSource.AddHook(apiMessagesHandler);

            // Initialize watcher.
            _skypeWatcher = new Timer(WatchInterval);
            _skypeWatcher.Elapsed += skypeWatcherHandler;
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     this.handle = new WindowInteropHelper(this).Handle;            
     sourceHandle = HwndSource.FromHwnd(this.handle);
     
     // the hook allows to recieve Windows messages
     sourceHookHandle = new HwndSourceHook(WndProc);
     sourceHandle.AddHook(sourceHookHandle);
     
     // allows WndProc() to receive clipboard messages
     WinAPI.NativeMethods.AddClipboardFormatListener(this.handle);            
 }
Пример #24
0
        public void Load()
        {
            if (!IsUILoaded)
            {
                Init();

                source = PresentationSource.FromVisual(this) as HwndSource;
                source.AddHook(WndProc);

                IsUILoaded = true;
            }
        }
Пример #25
0
        public void Attach(Window window)
        {
            _parentWindow = window;
            _parentWindowHndl = new WindowInteropHelper(window).Handle;
            _source = HwndSource.FromHwnd(_parentWindowHndl);
            Debug.Assert(_source != null);
            _source.AddHook(ParentWndProc);

            _topGlow.Show();
            _bottomGlow.Show();
            _leftGlow.Show();
            _rightGlow.Show();
        }
Пример #26
0
 public GlobalHotkeyService()
 {
     // Static stuff is meh...
     Application.Current.Guard("Application.Current");
     Application.Current.MainWindow.Guard("Application.Current.MainWindow");
     var interopHelper = new WindowInteropHelper(Application.Current.MainWindow);
     interopHelper.EnsureHandle();
     source = HwndSource.FromHwnd(interopHelper.Handle);
     if (null == source)
     {
         Trace.WriteLine("Could not get HwndSource for the Shell");
         return;
     }
     source.AddHook(WndProc);
 }
Пример #27
0
        public HiddenWindow(EPdeviceManager deviceManager)
        {
            _EPdevices = deviceManager;

            hwnd = new WindowInteropHelper(this).EnsureHandle(); //.Handle;
            source = HwndSource.FromHwnd(hwnd);
            if (source != null)
            {
                hook = new HwndSourceHook(WndProc);
                source.AddHook(hook);
            }

            _EPdevices.Initialize(hwnd);

            this.Visibility = Visibility.Hidden;
        }
Пример #28
0
        //安装热键处理挂钩
        static private bool InstallHotKeyHook(HotKey hk)
        {
            if (hk.Window == null || hk.Handle == IntPtr.Zero)
            {
                return(false);
            }

            //获得消息源
            System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(hk.Handle);
            if (source == null)
            {
                return(false);
            }

            //挂接事件
            source.AddHook(HotKey.HotKeyHook);
            return(true);
        }
Пример #29
0
 public bool InstallHotKeyHook(Window window)
 {
     if (window == null)
     {
         return(false);
     }
     System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(window);
     if (IntPtr.Zero == helper.Handle)
     {
         return(false);
     }
     System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(helper.Handle);
     if (source == null)
     {
         return(false);
     }
     source.AddHook(this.HotKeyHook);
     return(true);
 }
Пример #30
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Handle = new WindowInteropHelper((Window)sender).Handle;

            if (Handle != IntPtr.Zero)
            {
                HSource = HwndSource.FromHwnd(Handle);
                HSource.AddHook(new HwndSourceHook(WndProc));

                if (Environment.OSVersion.Version.Major >= 6)
                {
                    //Обходим UAC-фильтр
                    ChangeWindowMessageFilter(0x0233, 1); //WM_DROPFILES
                    ChangeWindowMessageFilter(0x004A, 1); //WM_COPYDATA
                    ChangeWindowMessageFilter(0x0049, 1); //WM_COPYGLOBALDATA
                }

                RevokeDragDrop(Handle);        //Выключаем OLE D&D (ВАЖНО!!!)
                DragAcceptFiles(Handle, true); //Включаем Win32 D&D
            }
        }
Пример #31
0
		void CreateContext()
		{
			ClearContext(); // clear old context if necessary
			if (!textArea.Options.EnableImeSupport)
				return;
			hwndSource = (HwndSource)PresentationSource.FromVisual(this.textArea);
			if (hwndSource != null) {
				//currentContext = ImeNativeWrapper.ImmCreateContext();
				//previousContext = ImeNativeWrapper.AssociateContext(hwndSource, currentContext);
				currentContext = ImeNativeWrapper.GetContext(hwndSource);
				hwndSource.AddHook(WndProc);
				// UpdateCompositionWindow() will be called by the caret becoming visible
				
				var threadMgr = ImeNativeWrapper.GetTextFrameworkThreadManager();
				if (threadMgr != null) {
					// Even though the docu says passing null is invalid, this seems to help
					// activating the IME on the default input context that is shared with WPF
					threadMgr.SetFocus(null);
				}
			}
		}
Пример #32
0
 private void MainWindow_SourceInitialized(object sender, EventArgs e)
 {
     System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(new System.Windows.Interop.WindowInteropHelper(this).Handle);
     source.AddHook(new System.Windows.Interop.HwndSourceHook(WndProc));
 }
        void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= new RoutedEventHandler(OnLoaded);

            this.SetParentToMainWindowOf(Model.Root.Manager);

            _hwndSrc = HwndSource.FromDependencyObject(this) as HwndSource;
            _hwndSrcHook = new HwndSourceHook(FilterMessage);
            _hwndSrc.AddHook(_hwndSrcHook);
        }
Пример #34
0
        /// <summary>
        /// Attaches this adorner to the adorned element
        /// </summary>
        public void Attach()
        {
            if (attached) return;
            Log("Attach begin");

            if (!oneOfAssociatedElements.IsLoaded)
            {
                // Delay attaching
                oneOfAssociatedElements.Loaded += OnDelayAttach;
                return;
            }

            adornerLayer = GetAdornerLayer(oneOfAssociatedElements);
            if (adornerLayer == null) return;

            // Focus current adorned element
            // Keyboard.Focus(adornedElement);
            focusedElement = Keyboard.FocusedElement;
            if (focusedElement != null)
            {
                Log("Focus Attached to " + focusedElement.ToString());
                focusedElement.LostKeyboardFocus += OnFocusLost;
                focusedElement.PreviewKeyDown += OnPreviewKeyDown;
                focusedElement.PreviewTextInput += this.OnFocusedElementPreviewTextInput;
            }
            else Log("[!] Focus Setup Failed");
            GetTopLevelElement(oneOfAssociatedElements).PreviewMouseDown += OnInputActionOccured;

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

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


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

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

            attached = true;
            Log("Attach end");
        }
        private void PresentationSourceChangedHandler(object sender, SourceChangedEventArgs args)
        {
            if (args.NewSource != null)
            {
                var newSource = (HwndSource)args.NewSource;

                source = newSource;

                if (source != null)
                {
                    var notifyDpiChanged = !matrix.Equals(source.CompositionTarget.TransformToDevice);

                    matrix = source.CompositionTarget.TransformToDevice;
                    sourceHook = SourceHook;
                    source.AddHook(sourceHook);

                    if (notifyDpiChanged)
                    {
                        managedCefBrowserAdapter.NotifyScreenInfoChanged();
                    }
                }
            }
            else if (args.OldSource != null)
            {
                RemoveSourceHook();
            }
        }