public WindowOpeningListenerImpl() { shellHook = new ShellHookImpl(); shellHook.shellEvent += onWindowOpened; Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, onWindowOpened); }
/// <summary> /// A windows was brought to foreground /// </summary> /// <param name="shellObject"></param> /// <param name="hWnd"></param> private static void WindowActivated(ShellHook shellObject, IntPtr hWnd) { appQueue.Add(new WindowData() { HWnd = hWnd, EventType = 1 }); }
public shellHookHelper(Handler parentHandler) : base() { // Minimized metrics. This is required in order to use // shellhooks without explorer.exe SetTaskmanWindow(Handle); this.parentHandler = parentHandler; notificationMessage = ShellHook.RegisterWindowMessage( "SHELLHOOK"); ShellHook.RegisterShellHookWindow(Handle); MinimizedMetrics mm = new MinimizedMetrics { cbSize = (uint)Marshal.SizeOf(typeof(MinimizedMetrics)) }; IntPtr mmPtr = Marshal.AllocHGlobal(Marshal.SizeOf( typeof(MinimizedMetrics))); try { Marshal.StructureToPtr(mm, mmPtr, true); SystemParametersInfo(SPI.SPI_GETMINIMIZEDMETRICS, mm.cbSize, mmPtr, SPIF.None); mm.iArrange |= MinimizedMetricsArrangement.Hide; Marshal.StructureToPtr(mm, mmPtr, true); SystemParametersInfo(SPI.SPI_SETMINIMIZEDMETRICS, mm.cbSize, mmPtr, SPIF.None); } finally { Marshal.DestroyStructure(mmPtr, typeof(MinimizedMetrics)); Marshal.FreeHGlobal(mmPtr); } }
public GlobalHooks(IntPtr handle) { _Handle = handle; _CBT = new CBTHook(_Handle); _Shell = new ShellHook(_Handle); _CallWndProc = new CallWndProcHook(_Handle); _GetMsg = new GetMsgHook(_Handle); }
public GlobalHooks(IntPtr Handle) { _Handle = Handle; source = HwndSource.FromHwnd(Handle); source.AddHook(WndProc); _CBT = new CBTHook(_Handle); _Shell = new ShellHook(_Handle); _CallWndProc = new CallWndProcHook(_Handle); _GetMsg = new GetMsgHook(_Handle); }
public GlobalHooks(IntPtr Handle) { _Handle = Handle; _CBT = new CBTHook(_Handle); _Shell = new ShellHook(_Handle); _Keyboard = new KeyboardHook(_Handle); _Mouse = new MouseHook(_Handle); _KeyboardLL = new KeyboardLLHook(_Handle); _MouseLL = new MouseLLHook(_Handle); _CallWndProc = new CallWndProcHook(_Handle); _GetMsg = new GetMsgHook(_Handle); }
private void registerHotKeys() { //bind to clipboard ShellHook sh; ClipboardHelper ch; GlobalHotkeyHelper gh; System.Windows.Forms.Form f; f = new System.Windows.Forms.Form(); sh = new ShellHook(f.Handle); //sh.WindowActivated += sh_WindowActivated; //sh.RudeAppActivated += sh_WindowActivated; ch = new ClipboardHelper(f.Handle); ch.ClipboardGrabbed += ch_ClipboardGrabbed; ch.RegisterClipboardListener(); gh = new GlobalHotkeyHelper(f.Handle); gh.GlobalHotkeyFired += new GlobalHotkeyHandler(gh_GlobalHotkeyFired); //gh.RegisterHotKey(72783, KeyModifiers.Control, VirtualKeys.VK_COMMA); //gh.RegisterHotKey(72784, KeyModifiers.Alt, VirtualKeys.VK_PERIOD); gh.RegisterHotKey(72784, KeyModifiers.Control, VirtualKeys.VK_2); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); var settingsFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "SmartSystemMenu.xml"); if (File.Exists(settingsFileName)) { _settings = SmartSystemMenuSettings.Read(settingsFileName); } #if WIN32 if (Environment.Is64BitOperatingSystem) { string resourceName = "SmartSystemMenu.SmartSystemMenu64.exe"; string fileName = "SmartSystemMenu64.exe"; string directoryName = Path.GetDirectoryName(AssemblyUtils.AssemblyLocation); string filePath = Path.Combine(directoryName, fileName); try { if (!File.Exists(filePath)) { AssemblyUtils.ExtractFileFromAssembly(resourceName, filePath); } _64BitProcess = Process.Start(filePath); } catch { string message = string.Format("Failed to load {0} process!", fileName); MessageBox.Show(message, AssemblyUtils.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } } _systemTrayMenu = new SystemTrayMenu(); _systemTrayMenu.MenuItemAutoStart.Click += MenuItemAutoStartClick; _systemTrayMenu.MenuItemSettings.Click += MenuItemSettingsClick; _systemTrayMenu.MenuItemAbout.Click += MenuItemAboutClick; _systemTrayMenu.MenuItemExit.Click += MenuItemExitClick; _systemTrayMenu.MenuItemAutoStart.Checked = AutoStarter.IsAutoStartByRegisterEnabled(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation); #endif _windows = EnumWindows.EnumAllWindows(_settings.MenuItems, new string[] { SHELL_WINDOW_NAME }).ToList(); foreach (var window in _windows) { var processName = ""; try { processName = Path.GetFileName(window.Process.GetMainModuleFileName()); } catch { } if (string.IsNullOrEmpty(processName) || _settings.ProcessExclusions.Contains(processName.ToLower())) { continue; } window.Menu.Create(); int menuItemId = window.ProcessPriority.GetMenuItemId(); window.Menu.CheckMenuItem(menuItemId, true); window.Menu.SetMenuItemText(SystemMenu.SC_ALIGN_MONITOR, "Select Monitor: " + Screen.AllScreens.ToList().FindIndex(s => s.Primary)); if (window.AlwaysOnTop) { window.Menu.CheckMenuItem(SystemMenu.SC_TOPMOST, true); } } _getMsgHook = new GetMsgHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE); _getMsgHook.GetMsg += WindowGetMsg; _getMsgHook.Start(); _shellHook = new ShellHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE); _shellHook.WindowCreated += WindowCreated; _shellHook.WindowDestroyed += WindowDestroyed; _shellHook.Start(); _cbtHook = new CBTHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE); _cbtHook.WindowCreated += WindowCreated; _cbtHook.WindowDestroyed += WindowDestroyed; _cbtHook.MoveSize += WindowMoveSize; _cbtHook.MinMax += WindowMinMax; _cbtHook.Start(); _mouseHook = new MouseHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE); _mouseHook.Start(); Hide(); }
/// <summary> /// This is executed when the form is destroyed /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { try { ShellHook.DeregisterShellHookWindow(Handle); } catch { } base.Dispose(disposing); }
/// <summary> /// A windows was brought to foreground /// </summary> /// <param name="shellObject"></param> /// <param name="hWnd"></param> private void WindowActivated(ShellHook shellObject, IntPtr hWnd) { appQueue.Enqueue(new WindowData { HWnd = hWnd, EventType = 1 }); }
/// <summary> /// A windows was created on desktop /// </summary> /// <param name="shellObject"></param> /// <param name="hWnd"></param> private void WindowCreated(ShellHook shellObject, IntPtr hWnd) { appQueue.Enqueue(new WindowData { HWnd = hWnd, EventType = 0, CreationTime = DateTimeOffset.Now }); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); #if WIN32 if (Environment.Is64BitOperatingSystem) { var resourceName = "SmartSystemMenu.SmartSystemMenu64.exe"; var fileName = "SmartSystemMenu64.exe"; var directoryName = Path.GetDirectoryName(AssemblyUtils.AssemblyLocation); var filePath = Path.Combine(directoryName, fileName); try { if (!File.Exists(filePath)) { AssemblyUtils.ExtractFileFromAssembly(resourceName, filePath); } _64BitProcess = Process.Start(filePath); } catch { string message = string.Format("Failed to load {0} process!", fileName); MessageBox.Show(message, AssemblyUtils.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } } if (_settings.ShowSystemTrayIcon) { _systemTrayMenu = new SystemTrayMenu(_settings.Language); _systemTrayMenu.MenuItemAutoStartClick += MenuItemAutoStartClick; _systemTrayMenu.MenuItemSettingsClick += MenuItemSettingsClick; _systemTrayMenu.MenuItemAboutClick += MenuItemAboutClick; _systemTrayMenu.MenuItemExitClick += MenuItemExitClick; _systemTrayMenu.Create(); _systemTrayMenu.CheckMenuItemAutoStart(AutoStarter.IsAutoStartByRegisterEnabled(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation)); } var moduleName = Process.GetCurrentProcess().MainModule.ModuleName; _hotKeyHook = new HotKeyHook(); _hotKeyHook.Hooked += HotKeyHooked; if (_settings.MenuItems.Items.Flatten(x => x.Items).Any(x => x.Type == MenuItemType.Item && x.Key3 != VirtualKey.None && x.Show) || _settings.MenuItems.WindowSizeItems.Any(x => x.Key3 != VirtualKey.None)) { _hotKeyHook.Start(moduleName, _settings.MenuItems); } _hotKeyMouseHook = new HotKeys.MouseHook(); _hotKeyMouseHook.Hooked += HotKeyMouseHooked; if (_settings.Closer.MouseButton != MouseButton.None) { _hotKeyMouseHook.Start(moduleName, _settings.Closer.Key1, _settings.Closer.Key2, _settings.Closer.MouseButton); } #endif _windows = EnumWindows.EnumAllWindows(_settings, _windowSettings, new string[] { SHELL_WINDOW_NAME }).ToList(); foreach (var window in _windows) { var processPath = window.Process?.GetMainModuleFileName() ?? string.Empty; var fileName = Path.GetFileName(processPath); if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName.ToLower())) { continue; } var isAdded = window.Menu.Create(); if (isAdded) { window.Menu.CheckMenuItem(window.ProcessPriority.GetMenuItemId(), true); if (window.AlwaysOnTop) { window.Menu.CheckMenuItem(MenuItemId.SC_TOPMOST, true); } if (window.IsExToolWindow) { window.Menu.CheckMenuItem(MenuItemId.SC_HIDE_FOR_ALT_TAB, true); } var windowClassName = window.GetClassName(); var states = _windowSettings.Find(windowClassName, processPath); if (states.Any()) { window.ApplyState(states[0], _settings.SaveSelectedItems, _settings.MenuItems.WindowSizeItems); window.Menu.CheckMenuItem(MenuItemId.SC_SAVE_SELECTED_ITEMS, true); } } } _callWndProcHook = new CallWndProcHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE); _callWndProcHook.CallWndProc += WindowProc; _callWndProcHook.Start(); _getMsgHook = new GetMsgHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE); _getMsgHook.GetMsg += WindowGetMsg; _getMsgHook.Start(); _shellHook = new ShellHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE); _shellHook.WindowCreated += WindowCreated; _shellHook.WindowDestroyed += WindowDestroyed; _shellHook.Start(); _cbtHook = new CBTHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE); _cbtHook.WindowCreated += WindowCreated; _cbtHook.WindowDestroyed += WindowDestroyed; _cbtHook.MoveSize += WindowMoveSize; _cbtHook.MinMax += WindowMinMax; _cbtHook.Start(); _mouseHook = new Hooks.MouseHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE); var dragByMouseItemName = MenuItemId.GetName(MenuItemId.SC_DRAG_BY_MOUSE); if (_settings.MenuItems.Items.Flatten(x => x.Items).Any(x => x.Type == MenuItemType.Item && x.Name == dragByMouseItemName && x.Show)) { _mouseHook.Start(); } Hide(); }