public DefaultTaskbarWindowService(IAppSettings settings)
        {
            _hookInstance = this;

            Settings        = settings;
            ActivePlacement = settings.Placement;

            // install a win event hook to track taskbar resize/movement
            hookDelegate = new WinEventHook.WinEventDelegate(WinEventProc);
            var winHook = WinEventHook.SetHook(WinEventHook.EVENT_OBJECT_LOCATIONCHANGE, hookDelegate);

            Application.ApplicationExit += (s, e) =>
            {
                if (winHook != IntPtr.Zero)
                {
                    WinEventHook.RemoveHook(winHook);
                    winHook = IntPtr.Zero;

                    foreach (var f in GetWindows())
                    {
                        f.Close();
                        f.RestoreTaskbar();
                    }
                }
            };
        }
示例#2
0
        /// <summary>
        /// Applies various system hooks via SetWinEventHook
        /// </summary>
        private void HookHooks()
        {
            WinEventHook.WinEventDelegate procDelegate = new WinEventHook.WinEventDelegate(EventCallback);

            moveSizeEvent.Hook(procDelegate, Settings.processId, Settings.EVENT_SYSTEM_MOVESIZESTART, Settings.EVENT_SYSTEM_MOVESIZEEND);
            foregroundEvent.Hook(procDelegate, 0, Settings.EVENT_SYSTEM_FOREGROUND);
        }
示例#3
0
        protected void EnableAttactWindow()
        {
            if (_windowEventHook != IntPtr.Zero)
            {
                return;
            }

            try
            {
                WinEventHook.WinEventDelegate windowEventDelegate = new WinEventHook.WinEventDelegate(AttachWindowEventCallback);
                _windowEventGCHandle = GCHandle.Alloc(windowEventDelegate);
                _windowEventHook     = WinEventHook.WinEventHookOne(WinEventHook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                                    windowEventDelegate,
                                                                    (uint)_gameMemory.Process.Id,
                                                                    WinEventHook.GetWindowThread(_gameMemory.Process.WindowHandle));
            }
            catch (Exception ex)
            {
                Plugin.ShowExceptionMessage(ex);
            }

            if (_windowEventHook == IntPtr.Zero)
            {
                DisableAttactWindow();
            }
        }
        private bool CreateOverlay()
        {
            if (_isOverlayInitialized && !_isOverlayReady && _gameMemory.Process.WindowHandle != IntPtr.Zero)
            {
                _window.Create();

                _graphics.Width        = _window.Width;
                _graphics.Height       = _window.Height;
                _graphics.WindowHandle = _window.Handle;
                _graphics.Setup();

                _window.SizeChanged += (object sender, OverlaySizeEventArgs e) =>
                                       _graphics.Resize(_window.Width, _window.Height);

                _window.FitTo(_gameMemory.Process.WindowHandle, true);

                if (_windowEventDispatcher != null)
                {
                    _windowEventDispatcher.Invoke(delegate
                    {
                        WinEventHook.WinEventDelegate windowEventDelegate = new WinEventHook.WinEventDelegate(MoveGameWindowEventCallback);
                        _windowEventGCHandle = GCHandle.Alloc(windowEventDelegate);
                        _windowEventHook     = WinEventHook.WinEventHookOne(WinEventHook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                                            windowEventDelegate,
                                                                            (uint)_gameMemory.Process.Id,
                                                                            WinEventHook.GetWindowThread(_gameMemory.Process.WindowHandle));
                    });
                }

                //Get a refernence to the underlying RenderTarget from SharpDX. This'll be used to draw portions of images.
                _device = (SharpDX.Direct2D1.WindowRenderTarget) typeof(Graphics)
                          .GetField("_device", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
                          .GetValue(_graphics);

                _consolas14Bold = _graphics.CreateFont("Consolas", 14, true);
                _consolas16Bold = _graphics.CreateFont("Consolas", 16, true);
                _consolas32Bold = _graphics.CreateFont("Consolas", 32, true);

                _black      = _graphics.CreateSolidBrush(0, 0, 0, Config.Opacity);
                _white      = _graphics.CreateSolidBrush(255, 255, 255, Config.Opacity);
                _green      = _graphics.CreateSolidBrush(0, 128, 0, Config.Opacity);
                _lawngreen  = _graphics.CreateSolidBrush(124, 252, 0, Config.Opacity);
                _red        = _graphics.CreateSolidBrush(255, 0, 0, Config.Opacity);
                _darkred    = _graphics.CreateSolidBrush(139, 0, 0, Config.Opacity);
                _grey       = _graphics.CreateSolidBrush(128, 128, 128, Config.Opacity);
                _darkergrey = _graphics.CreateSolidBrush(60, 60, 60, Config.Opacity);
                _gold       = _graphics.CreateSolidBrush(255, 215, 0, Config.Opacity);
                _goldenrod  = _graphics.CreateSolidBrush(218, 165, 32, Config.Opacity);
                _violet     = _graphics.CreateSolidBrush(238, 130, 238, Config.Opacity);

                _characterSheet = ImageLoader.LoadBitmap(_device, Properties.Resources.portraits);
                _inventorySheet = ImageLoader.LoadBitmap(_device, Properties.Resources.objects);

                _isOverlayReady = true;
            }

            return(_isOverlayReady);
        }
示例#5
0
 public static extern IntPtr SetWinEventHook(WinEventHook.SWEH_Events eventMin, WinEventHook.SWEH_Events eventMax,
                                             IntPtr hmodWinEventProc, WinEventHook.WinEventDelegate lpfnWinEventProc,
                                             uint idProcess, uint idThread, WinEventHook.SWEH_dwFlags dwFlags);