protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource?source = PresentationSource.FromVisual(this) as HwndSource; source?.AddHook(WndProc); // Get GameView window handle var interopHelper = new WindowInteropHelper(this); DataRepository.GameViewHandle = interopHelper.Handle; RegisterAppBar(false); // Alaways make window front DispatcherTimer timer = new DispatcherTimer(); var pointer = new WindowInteropHelper(this); timer.Tick += (sender, _) => { if (pointer.Handle == IntPtr.Zero) { timer.Stop(); } if (DataRepository.MainProcess?.MainWindowHandle == NativeMethods.GetForegroundWindow()) { NativeMethods.BringWindowToTop(pointer.Handle); } }; timer.Interval = TimeSpan.FromMilliseconds(50); timer.Start(); }
/// <summary> /// When the SourceInitialized event is raised, add a hook so that we can /// watch the WndProc event queue. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource?source = PresentationSource.FromVisual(this) as HwndSource; source?.AddHook(WndProc); }
private void Window_SourceInitialized(object sender, EventArgs e) { WindowInteropHelper helper = new WindowInteropHelper(this); HwndSource source = HwndSource.FromHwnd(helper.Handle); source?.AddHook(WndProc); cboDesktopBackgroundType_SelectionChanged(null, null); NativeMethods.SetForegroundWindow(helper.Handle); }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { IsRadioButtonUseTannerHellandAlgorithmChecked = true; SelectedColor = _selectedColor; Configs = new ObservableCollection <Config>(_configService.GetConfigs().OrderBy(conf => conf.Order)); if (Configs.Count > 0) { SelectedConfig = Configs[0]; } RegistryKey key = Registry.CurrentUser.OpenSubKey(RunKeyPath, true); if (key != null) { string applicationName = Process.GetCurrentProcess().ProcessName; object subKey = key.GetValue(applicationName); IsCheckboxStartAtSystemStartupChecked = subKey != null; key.Close(); } _windowHandle = (new WindowInteropHelper(this)).Handle; HwndSource src = HwndSource.FromHwnd(_windowHandle); src?.AddHook(WndProc); foreach (Config conf in Configs) { if (conf.KeyBinding != null) { uint mask = conf.KeyBinding.Alt ? (uint)0x0001 : 0; mask = mask | (conf.KeyBinding.Control ? (uint)0x0002 : 0); mask = mask | (conf.KeyBinding.Shift ? (uint)0x0004 : 0); mask = mask | 0x4000; int virtualKeyCode = KeyInterop.VirtualKeyFromKey(conf.KeyBinding.Key); if (!RegisterHotKey(_windowHandle, virtualKeyCode, mask, (uint)virtualKeyCode)) { MessageBox.Show("Cannot bind key " + conf.KeyBinding); } } } WindowState = WindowState.Minimized; }
private void Loaded(Window win) { if (_hwndSourceHook == null) { _hwndSourceHook = new HwndSourceHook(WndProc); } _hwndSource?.Dispose(); _hwndSource = PresentationSource.FromVisual(win) as HwndSource; _hwndSource?.AddHook(_hwndSourceHook); }
/// <summary> /// OnSourceInitialized /// </summary> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); ManageChromeBorder(); ManageTitleBarBackground(); ManageTitleBarContent(); ManageTitleBarCaptionButtons(); _targetSource = PresentationSource.FromVisual(this) as HwndSource; _targetSource?.AddHook(WndProc); }
private void OnSourceInitialized(object sender, EventArgs e) { _source = PresentationSource.FromVisual(_window) as HwndSource; _source?.AddHook(WndProc); var dpi = VisualTreeHelperAddition.GetDpi(_window); if (!dpi.Equals(VisualTreeHelperAddition.SystemDpi)) { AdjustWindow(dpi); } }
private void AddSystemMenuItems() { IntPtr windowHandle = new WindowInteropHelper(this).Handle; IntPtr systemMenu = GetSystemMenu(windowHandle, false); InsertMenu(systemMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty); InsertMenu(systemMenu, 6, MF_BYPOSITION, _UpdateSysMenuID, "Check for Updates..."); InsertMenu(systemMenu, 7, MF_BYPOSITION, _AboutSysMenuID, "About..."); HwndSource source = HwndSource.FromHwnd(windowHandle); source.AddHook(new HwndSourceHook(WndProc)); }
private void MenuBarShadow_Loaded(object sender, RoutedEventArgs e) { WindowInteropHelper helper = new WindowInteropHelper(this); HwndSource source = HwndSource.FromHwnd(helper.Handle); source.AddHook(new HwndSourceHook(WndProc)); // Makes click-through by adding transparent style // basically same as Shell.HideWindowFromTasks(helper.Handle); NativeMethods.SetWindowLong(helper.Handle, NativeMethods.GWL_EXSTYLE, NativeMethods.GetWindowLong(helper.Handle, NativeMethods.GWL_EXSTYLE) | (int)NativeMethods.ExtendedWindowStyles.WS_EX_TOOLWINDOW | (int)NativeMethods.ExtendedWindowStyles.WS_EX_TRANSPARENT); Shell.ExcludeWindowFromPeek(helper.Handle); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); // Adds the windows message processing hook and registers USB device add/removal notification. HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); if (source != null) { windowHandle = source.Handle; source.AddHook(HwndHandler); UsbNotification.RegisterUsbDeviceNotification(windowHandle); } }
private void Init(HwndSource hwndSource) { if (hwndSource == null) { throw new ArgumentNullException("hwndSource"); } this.hook = new HwndSourceHook(WndProc); this.hwndSource = hwndSource; hwndSource.AddHook(hook); IsEnabled = true; }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); _hwndSource = (HwndSource)PresentationSource.FromVisual(this); if (_hwndSource == null) { throw new Exception("Error getting glow window handle"); } _hwndSource.AddHook(WndProc); _handle = _hwndSource.Handle; }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); // Hook into the message pump HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); if (source != null) { source.AddHook(HwndHandler); DeviceEventMonitor.RegisterDeviceNotification(source.Handle); } }
void win_SourceInitialized(object sender, System.EventArgs e) { var handle = (new WindowInteropHelper(AssociatedObject)).Handle; hwndSource = HwndSource.FromHwnd(handle); if (hwndSource == null) { return; } hwndSource.AddHook(WindowProc); }
void DemoWpfControl_Loaded(object sender, RoutedEventArgs e) { if (mHwndSource != null) { return; } mHwndSource = PresentationSource.FromVisual(this) as HwndSource; if (mHwndSource != null) { mHwndSource.AddHook(WndProc); } }
public void StartListening() { IntPtr windowHandle = (new WindowInteropHelper(listeningWindow)).Handle; if (windowHandle == IntPtr.Zero) { throw new InvalidOperationException("The listening window cannot be found. Make this call from the 'Loaded' event instead of the constructor, since the window is not actualy created yet in constructor."); } HwndSource src = HwndSource.FromHwnd(windowHandle); src.AddHook(new HwndSourceHook(WndProc)); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); if (NotiCenterWindowViewModel.IsHotKeyEnabled) { _thisWindowHandle = new WindowInteropHelper(this).Handle; HwndSource hWndSource = HwndSource.FromHwnd(_thisWindowHandle); if (hWndSource != null) { hWndSource.AddHook(WndProc); } } }
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(); }
void MainWindow_SourceInitialized(object sender, EventArgs e) { customBorderThickness = int.Parse(windows_main.BorderThickness.Right.ToString()); HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); if (source == null) { // Should never be null throw new Exception("Cannot get HwndSource instance."); } source.AddHook(new HwndSourceHook(this.WndProc)); }
/// <summary> /// Register WindowHandle to process WM_Gesture Messages /// </summary> public void RegisterHandleForGestures() { HwndSource hwnd = HwndSource.FromHwnd(_handle); if (hwnd != null) { hwnd.AddHook(MessageProc); } else { Debug.Print("HWND is null"); } }
public SystemEvents() { Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; // window used to hook into wndproc Window win = new(); WindowInteropHelper helper = new(win); HwndSource source = HwndSource.FromHwnd(helper.EnsureHandle()); RegisterAppBar(source.Handle); source.AddHook(WndProc); }
//============================================================================= private void StartupWindow_SourceInitialized(object sender, EventArgs e) { // m_WndHandle = new WindowInteropHelper(this).Handle; WindowsUtils.DisableMaximizeButton(m_WndHandle); WindowsUtils.EnableMinimizeButton(m_WndHandle); // WindowInteropHelper helper = new WindowInteropHelper(this); HwndSource source = HwndSource.FromHwnd(helper.Handle); source.AddHook(WndProc); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); _windowHandle = new WindowInteropHelper(this).Handle; Handle = _windowHandle; _source = HwndSource.FromHwnd(_windowHandle); _source.AddHook(HookCallbackManager.WindowsKeyHookCallback); WinApiProxy.RegisterHotKey(_windowHandle, KeyHookConstants.HOTKEY_ID, KeyHookConstants.MOD_ALT, KeyHookConstants.VK_OEM_COMMA); //ALT + , _windowEventCallback = HookCallbackManager.WindowsWindowCreatedHook; HookManager.RegisterCallBack(ref _windowEventCallback); HookManager.SubscribeToWindowEvents(); }
public void ToggleListener() { if (SettingsService.Get <bool>("IsUsingAutomaticRefresh")) { _hwndSource.AddHook(OnClipboardChanged); _hwndNextViewer = SetClipboardViewer(_hwndSource.Handle); } else { _hwndSource.RemoveHook(OnClipboardChanged); ChangeClipboardChain(_hwndSource.Handle, _hwndNextViewer); } }
/// <summary> /// WPF窗体的资源初始化完成,并且可以通过WindowInteropHelper获得该窗体的句柄用来与Win32交互后调用 /// </summary> /// <param name="e"></param> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); // 获取窗体句柄 m_Hwnd = new WindowInteropHelper(this).Handle; HwndSource hWndSource = HwndSource.FromHwnd(m_Hwnd); // 添加处理程序 if (hWndSource != null) { hWndSource.AddHook(WndProc); } }
private void Window_SourceInitialized(object sender, EventArgs e) { var windowInteropHelper = new WindowInteropHelper(this); var hwnd = windowInteropHelper.Handle; //ExInputSink flag makes it work even when not in foreground, similar to global hook.. but asynchronous, no complications & no AV false detection! RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.ExInputSink, hwnd); HwndSource source = HwndSource.FromHwnd(hwnd); source.AddHook(Hook); }
protected override void OnSourceInitialized(EventArgs args) { base.OnSourceInitialized(args); _windowHandle = new WindowInteropHelper(this).Handle; _hwndSource = HwndSource.FromHwnd(_windowHandle); _hwndSource?.AddHook(HwndHook); //Win32Api.RegisterHotKey(_windowHandle, OPEN_HOTKEY_ID, MOD_SHIFT, VK_SPACE); //TODO: Use hotkey from settings Win32Api.RegisterHotKey(_windowHandle, Win32Api.HotkeyId.OPEN_HOTKEY_ID, Win32Api.KeyCodes.MOD_ALT, Win32Api.KeyCodes.VK_SPACE); Win32Api.RegisterHotKey(_windowHandle, Win32Api.HotkeyId.PASTE_HOTKEY_ID, Win32Api.KeyCodes.MOD_ALT, Win32Api.KeyCodes.VK_V); Win32Api.AddClipboardFormatListener(_windowHandle); }
/// <summary> ///初始化系统热键对象 /// </summary> /// <param name="hwnd">窗口句柄</param> public SystemHotKeyWPF(IntPtr hwnd) { _hwnd = hwnd; hwndSource = HwndSource.FromHwnd(_hwnd); if (hwndSource != null) { hwndSource.AddHook(new HwndSourceHook(this.WndProc)); } else { throw new Exception("AddHook failed, can not create HwndSource"); } }
public void OnSourceInitialized() { _windowHandle = new WindowInteropHelper(_window).Handle; _source = HwndSource.FromHwnd(_windowHandle); _source?.AddHook(HwndHook); foreach (var hk in _hotkeys) { RegisterHotKey(_windowHandle, hk.Item3, hk.Item1, hk.Item2); } init = true; }
public WindowSnapManager(IntPtr hwnd) { _hwnd = HwndSource.FromHwnd(hwnd); if (_hwnd == null) { throw new InvalidOperationException("Unable to obtain HwndSource"); } // Add a WndProc hook in order to learn when the window is about to be moved or resized. // We then capture location info for all other open Paragon windows and use that to perform // window snapping operations. _hwnd.AddHook(WndProc); }