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

            return(rect);
        }
Beispiel #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);
     }
 }
Beispiel #4
0
 public static extern bool GetWindowRect(IntPtr hWnd, ref WinApi.RECT lpRect);