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 static WinApi.RECT GetWindowRect(IntPtr hWnd)
        {
            WinApi.RECT rect    = new WinApi.RECT();
            bool        _result = SafeNativeMethods.GetWindowRect(hWnd, ref rect);

            return(rect);
        }
Esempio n. 3
0
 protected void WinEventCallback(IntPtr hWinEventHook,
                                 Hook.SWEH_Events eventType,
                                 IntPtr hWnd,
                                 Hook.SWEH_ObjectId idObject,
                                 long idChild,
                                 uint dwEventThread,
                                 uint dwmsEventTime)
 {
     if (hWnd == NotepadhWnd &&
         eventType == Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE &&
         idObject == (Hook.SWEH_ObjectId)Hook.SWEH_CHILDID_SELF)
     {
         WinApi.RECT rect = Hook.GetWindowRect(hWnd);
         this.Location = new Point(rect.Right, rect.Top);
     }
 }
Esempio n. 4
0
 public static extern bool GetWindowRect(IntPtr hWnd, ref WinApi.RECT lpRect);