void HotKeyManager_RunXMove(object sender, MouseEventExtArgs e)
        {
            var hWnd    = WinApi.WindowFromPoint(e.Location);
            var hParent = IntPtr.Zero;

            if (hWnd == IntPtr.Zero)
            {
                return;
            }
            while (true)
            {
                hParent = WinApi.GetParent(hWnd);
                if (hParent == IntPtr.Zero)
                {
                    break;
                }
                hWnd = hParent;
            }
            if (!WinApi.IsWindow(hWnd))
            {
                return;
            }

            WinApi.RECT r = new WinApi.RECT();
            WinApi.GetWindowRect(hWnd, out r);
            offsetMoveWindow = new Point(e.X - r.Left, e.Y - r.Top);
            hWndMoveWindow   = hWnd;
            isXMove          = true;
        }
        private static void GetWindowInfo(IntPtr hWnd, bool isInFocus = false)
        {
            // http://www.codeproject.com/Articles/1698/MS-Spy-style-Window-Finder
            if (hWnd != IntPtr.Zero && WinApi.IsWindow(hWnd) && hWnd != hWndFoundWindow)
            {
                WindowSelectorEventArgs e = new WindowSelectorEventArgs();

                //Программа
                int pId;
                var threadId = WinApi.GetWindowThreadProcessId(hWnd, out pId);
                using (var p = Process.GetProcessById(pId))
                    e.ProgramName = p.MainModule.ModuleName;

                if (isInFocus)
                {
                    e.HGetForegroundWindow = (int)hWnd;
                    var h = Misc.GetFocusedHandle(threadId, e);
                    if (h != IntPtr.Zero)
                    {
                        hWnd = h;
                    }
                    if (hWnd == hWndFoundWindow)
                    {
                        return;
                    }
                }

                //Класс
                var temp = new StringBuilder(256);
                WinApi.GetClassName(hWnd, temp, temp.Capacity);
                e.ClassName = temp.ToString();
                temp.Clear();

                //Заголовок
                temp.Capacity = 256;
                WinApi.GetWindowText(hWnd, temp, temp.Capacity);
                e.WindowCaption = temp.ToString();
                temp.Clear();

                //Дескриптор
                e.HWindow = (int)hWnd;
                e.HParent = (int)WinApi.GetParent(hWnd);

                //Очищаем
                RefreshWindow(hWndFoundWindow);

                //Рисуем прямоугольник
                HighlightFoundWindow(hWnd);

                hWndFoundWindow = hWnd;

                if (UiUpdate != null)
                {
                    UiUpdate.Invoke(null, e);
                }
            }
        }
 private static void RefreshWindow(IntPtr hWnd)
 {
     if (hWnd != IntPtr.Zero && WinApi.IsWindow(hWnd))
     {
         WinApi.InvalidateRect(hWnd, IntPtr.Zero, true);
         WinApi.UpdateWindow(hWnd);
         WinApi.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero,
                             WinApi.RedrawWindowFlags.Frame |
                             WinApi.RedrawWindowFlags.Invalidate |
                             WinApi.RedrawWindowFlags.UpdateNow |
                             WinApi.RedrawWindowFlags.AllChildren);
     }
 }