public HorizontalMouseScrollHelper(ScrollViewer scrollviewer, DependencyObject d) { scrollViewer = scrollviewer; source = (HwndSource)PresentationSource.FromDependencyObject(d); if (source != null) source.AddHook(WindowProc); }
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); }
/// <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); }
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 } //
private void ShadowedWindow_OnLoaded(object sender, RoutedEventArgs e) { hwndSource = PresentationSource.FromVisual((Visual) sender) as HwndSource; if (hwndSource != null) hwndSource.AddHook(WndProc); }
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); } })); }
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 }
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); } }
public HotKey(HwndSource hwndSource) { hook = WndProc; this.hwndSource = hwndSource; hwndSource.AddHook(hook); var rand = new Random((int)DateTime.Now.Ticks); id = rand.Next(); }
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(); }
private void RegisterHotKey() { IntPtr hwnd = new WindowInteropHelper(this).Handle; //获得消息源 System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(hwnd); source.AddHook(HotKeyHook); }
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)); }; }
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 }
/// <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); }
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; }
//============================================================================= 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)); } } }
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); }
/// <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); }
public void Load() { if (!IsUILoaded) { Init(); source = PresentationSource.FromVisual(this) as HwndSource; source.AddHook(WndProc); IsUILoaded = true; } }
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(); }
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); }
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; }
//安装热键处理挂钩 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); }
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); }
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 } }
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); } } }
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); }
/// <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(); } }