private void GetCharacteristics()
        {
            User32Windows.GetWindowRect(m_Hwnd, out m_WindowRect);

            txtCurrentLeft.Text   = m_WindowRect.Left.ToString();
            txtCurrentTop.Text    = m_WindowRect.Top.ToString();
            txtCurrentWidth.Text  = (m_WindowRect.Width - m_WindowRect.Left).ToString();
            txtCurrentHeight.Text = (m_WindowRect.Height - m_WindowRect.Top).ToString();
        }
Exemple #2
0
        private void ProcessWindows()
        {
            Point p = Cursor.Position;

            foreach (var h in m_TrackedWindows)
            {
                Rectangle r;
                User32Windows.GetWindowRect(h, out r);

                if (p.X >= r.X && p.X <= r.Width &&
                    p.Y >= r.Y && p.Y <= r.Height)
                {
                    var hCurrent = User32Windows.GetForegroundWindow();
                    if (hCurrent != h)
                    {
                        User32Windows.SetForegroundWindow(h);
                    }

                    break;
                }
            }
        }
Exemple #3
0
        private void CalculateCoordinates()
        {
            Rectangle rHost;

            User32Windows.GetWindowRect(m_HostWindowHwnd, out rHost);

            if (m_AnchorH == AnchorHorizontal.Left)
            {
                m_HostWindowOffsetX = this.Location.X - rHost.Left;
            }
            else
            {
                m_HostWindowOffsetX = this.Location.X - rHost.Width;
            }

            if (m_AnchorV == AnchorVertical.Top)
            {
                m_HostWindowOffsetY = this.Location.Y - rHost.Top;
            }
            else
            {
                m_HostWindowOffsetY = this.Location.Y - rHost.Height;
            }
        }
Exemple #4
0
        private void CheckToolDisplaying()
        {
            if (!m_IsRunning)
            {
                return;
            }

            IntPtr foreWindow          = User32Windows.GetForegroundWindow();
            var    title               = User32Windows.GetWindowText(foreWindow, 255);
            bool   matchesTitlePattern = false;

            if (((foreWindow == m_HostWindowHwnd || foreWindow == this.Handle) &&
                 !User32Windows.IsIconic(m_HostWindowHwnd)) ||
                (title == m_HostWindowTitle && m_RunOnAllWindowsWithSameTitle) ||
                (m_TitlePattern != String.Empty && (matchesTitlePattern = m_TitleRegex.IsMatch(title))))
            {
                // if ((foreWindow != m_HostWindowHwnd) && (foreWindow != this.Handle))
                // {
                //     int pidFore, pidThis;
                //     User32Windows.GetWindowThreadProcessId(foreWindow, out pidFore);
                //     User32Windows.GetWindowThreadProcessId(this.Handle, out pidThis);
                //     if (pidFore == pidThis)
                //     {
                //         return;
                //     }
                //
                //     m_HostWindowHwnd = foreWindow;
                //     m_HostWindowTitle = title;
                //     if (!matchesTitlePattern)
                //     {
                //         CalculateCoordinates();
                //     }
                // }

                Rectangle rHost;
                User32Windows.GetWindowRect(m_HostWindowHwnd, out rHost);

                int newX = 0,
                    newY = 0;

                if (m_AnchorH == AnchorHorizontal.Left)
                {
                    newX = rHost.Left + m_HostWindowOffsetX;
                }
                else
                {
                    newX = rHost.Width + m_HostWindowOffsetX;
                }

                if (m_AnchorV == AnchorVertical.Top)
                {
                    newY = rHost.Top + m_HostWindowOffsetY;
                }
                else
                {
                    newY = rHost.Height + m_HostWindowOffsetY;
                }

                if ((this.Location.X != newX) || (this.Location.Y != newY))
                {
                    this.Location = new Point(newX, newY);
                }

                if (!this.Visible)
                {
                    Task.Delay(timer1.Interval).ContinueWith(t => this.Show());
                }
            }
            else if ((!m_RunOnAllWindowsWithSameTitle) && (!User32Windows.IsWindow(m_HostWindowHwnd)))
            {
                if (this.Exit != null)
                {
                    this.Exit.Invoke(this, new ToolEventArgs()
                    {
                        Title = m_HostWindowTitle
                    });
                }
                this.Close();
            }
            else if (User32Windows.IsIconic(m_HostWindowHwnd))
            {
                this.Hide();
            }
            else
            {
                Rectangle rForeWindow;
                User32Windows.GetWindowRect(foreWindow, out rForeWindow);

                var r        = this.RectangleToScreen(this.DisplayRectangle);
                var contains = RectangleContains(rForeWindow, r) ||
                               RectangleIntersects(rForeWindow, r);

                int processId,
                    ptocessIdThis;
                User32Windows.GetWindowThreadProcessId(foreWindow, out processId);
                User32Windows.GetWindowThreadProcessId(this.Handle, out ptocessIdThis);

                if (this.Visible && m_AutoHide && contains && (processId != ptocessIdThis))
                {
                    this.Hide();
                }
            }
        }