Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);

            try
            {
                Target = Process.GetProcessesByName("notepad").FirstOrDefault(p => p != null);
                if (Target != null)
                {
                    NotepadhWnd = Target.MainWindowHandle;
                    uint TargetThreadId = Hook.GetWindowThread(NotepadhWnd);

                    if (NotepadhWnd != IntPtr.Zero)
                    {
                        hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                             WinEventDelegate,
                                                             (uint)Target.Id,
                                                             TargetThreadId);
                        rect          = Hook.GetWindowRect(NotepadhWnd);
                        this.Location = new Point(rect.Right, rect.Top);
                    }
                }
            }
            catch (Exception ex)
            {
                //ErrorManager.Logger(this, this.InitializeComponent(), ex.HResult, ex.Data, DateTime.Now);
                throw ex;
            }
        }
Esempio n. 2
0
        public Form1()
        {
            InitializeComponent();
            WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);
            GCSafetyHandle   = GCHandle.Alloc(WinEventDelegate);

            try
            {
                targetProc = Process.GetProcessesByName("notepad").FirstOrDefault(p => p != null);
                if (targetProc != null)
                {
                    notepadhWnd = targetProc.MainWindowHandle;
                    uint targetThreadId = Hook.GetWindowThread(notepadhWnd);

                    if (notepadhWnd != IntPtr.Zero)
                    {
                        hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                             WinEventDelegate,
                                                             (uint)targetProc.Id,
                                                             targetThreadId);
                        rect          = Hook.GetWindowRect(notepadhWnd);
                        this.Location = new System.Drawing.Point(rect.Right, rect.Top);
                    }
                }
            }
            catch (Exception ex)
            {
                //ErrorManager.Logger(this, this.InitializeComponent(), ex.HResult, ex.Data, DateTime.Now);
                throw ex;
            }
        }
Esempio n. 3
0
        public StashGridHighlight()
        {
            // Verify that POE is a running process.
            if (poeHandle == IntPtr.Zero)
            {
                MessageBox.Show("Path of Exile is not running.");
                return;
            }

            InitializeComponent();

            Loaded += (object sender, RoutedEventArgs e) => SetNoActiveWindow();

            UpdateLocationAndSize();

            WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);

            try
            {
                if (poeHandle != IntPtr.Zero)
                {
                    uint TargetThreadId = Hook.GetWindowThread(poeHandle);
                    UnsafeNativeMethods.GetWindowThreadProcessId(poeHandle, out poeProcessId);
                    hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                         WinEventDelegate,
                                                         poeProcessId,
                                                         TargetThreadId);
                }
            }
            catch (Exception ex)
            {
                //ErrorManager.Logger(this, this.InitializeComponent(), ex.HResult, ex.Data, DateTime.Now);
                throw ex;
            }
        }
Esempio n. 4
0
        public OverlayForm()
        {
            InitializeComponent();

            _winEventMoveDelegate = new Hook.WinEventDelegate(WinEventMoveCallback);
            _GCSafetyMoveHandle   = GCHandle.Alloc(_winEventMoveDelegate);

            _winEventForegroundDelegate = new Hook.WinEventDelegate(WinEventForegroundCallback);
            _GCSafetyForegroundHandle   = GCHandle.Alloc(_winEventForegroundDelegate);
        }
        public StashGridHighlight()
        {
            CheckAndUpdate();

            // Verify that POE is a running process.
            if (poeHandle == IntPtr.Zero)
            {
                MessageBox.Show("Path of Exile is not running.");
                return;
            }

            InitializeComponent();

            Loaded += (object sender, RoutedEventArgs e) => SetNoActiveWindow();

            UpdateLocationAndSize();

            WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);
        }
Esempio n. 6
0
    public Test(Form toCover, AxAXVLC.AxVLCPlugin2 ply)
    {
        InitializeComponent();
        WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);
        this.SetTopLevel(true);
        this.TopMost       = true;
        this.ControlBox    = false;
        this.ShowInTaskbar = false;
        this.StartPosition = FormStartPosition.Manual;
        this.AutoScaleMode = AutoScaleMode.None;
        this.Show(toCover);
        toCover.Focus();

        try
        {
            Target = Process.GetProcessesByName("TestPlayer").FirstOrDefault(p => p != null);
            if (Target != null)
            {
                testPic = Target.MainWindowHandle;
                uint TargetThreadId = Hook.GetWindowThread(testPic);
                if (testPic != IntPtr.Zero)
                {
                    hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                         WinEventDelegate,
                                                         (uint)Target.Id,
                                                         TargetThreadId);
                    rect = Hook.GetWindowRect(testPic);
                }
                if (ply.video.fullscreen == true)
                {
                    Debug.WriteLine("yes is ");
                    this.WindowState = FormWindowState.Maximized;
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
    }
Esempio n. 7
0
 public static extern IntPtr SetWinEventHook(Hook.SWEH_Events eventMin, Hook.SWEH_Events eventMax,
                                             IntPtr hmodWinEventProc, Hook.WinEventDelegate lpfnWinEventProc,
                                             uint idProcess, uint idThread, Hook.SWEH_dwFlags dwFlags);
Esempio n. 8
0
        private void SetGameWindowHook()
        {
            WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);
            GCSafetyHandle   = GCHandle.Alloc(WinEventDelegate);

            var gameInfo   = (GameInfo)SimpleIoc.Default.GetInstance(typeof(GameInfo));
            var targetProc = gameInfo.HWndProc;

            targetProc.EnableRaisingEvents = true;
            targetProc.Exited += new EventHandler(Window_Closed);
            Closed            += Window_Closed;

            gameHWnd = targetProc.MainWindowHandle;

            // TODO: hardcode for 参千世界遊戯 check fullscrenn changed single, then do handle search
            // Then call WinEventDelegate send threadId of handle
            // 找窗口是否全屏还不太容易,不能使用handle的方法、最好查找有无什么事件。。
            //if MainWindowHandle has no window
            IntPtr handle      = targetProc.MainWindowHandle;
            var    defaultRect = Hook.GetClientRect(handle);

            if (0 == defaultRect.Bottom && defaultRect.Bottom == defaultRect.Right)
            {
                log.Info($"Can't find window Rect in MainWindowHandle! Start search..");
                log.Info($"Process {targetProc.Id} has {targetProc.HandleCount} handles");

                int           textLength = targetProc.MainWindowTitle.Length;
                StringBuilder title      = new StringBuilder(textLength + 1);
                Hook.GetWindowText(handle, title, title.Capacity);

                IntPtr first      = Hook.GetWindow(targetProc.MainWindowHandle, Hook.GW.HWNDFIRST);
                IntPtr last       = Hook.GetWindow(targetProc.MainWindowHandle, Hook.GW.HWNDLAST);
                IntPtr realHandle = IntPtr.Zero;
                for (IntPtr cur = first; cur != last; cur = Hook.GetWindow(cur, Hook.GW.HWNDNEXT))
                {
                    StringBuilder outText = new StringBuilder(textLength + 1);
                    Hook.GetWindowText(cur, outText, title.Capacity);
                    if (outText.Equals(title))
                    {
                        var rectClient = Hook.GetClientRect(cur);
                        if (rectClient.Right != 0 && rectClient.Bottom != 0)
                        {
                            log.Info($"Find real handle at 0x{Convert.ToString(cur.ToInt64(), 16).ToUpper()}");
                            realHandle = cur;
                            //var tmp = Hook.GetWindowRect(cur);
                            //log.Info($"{rectClient.Right} {rectClient.Bottom} {tmp.Left} {tmp.Top} {tmp.Right} {tmp.Bottom}");
                            //break;
                        }
                    }
                }
                if (realHandle != IntPtr.Zero)
                {
                    gameHWnd = realHandle;
                }
                // 如果再次报错 再次检查MainWindowHandle
                else
                {
                    throw new Exception("无法找到游戏的窗体handle!请再次尝试,或者联系开发者寻求帮助");
                }
            }

            log.Info($"Set handle to 0x{Convert.ToString(gameHWnd.ToInt64(), 16).ToUpper()} Title: {targetProc.MainWindowTitle}");
            uint targetThreadId = Hook.GetWindowThread(gameHWnd);

            dpi = VisualTreeHelper.GetDpi(this).DpiScaleX;

            if (gameHWnd != IntPtr.Zero)
            {
                // 调用 SetWinEventHook 传入 WinEventDelegate 回调函数
                hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                     WinEventDelegate,
                                                     (uint)targetProc.Id,
                                                     targetThreadId);
                // 首次设置窗口位置
                SetLocation();
                log.Info("Begin to follow the window");
                return;
            }
        }