public SendCommandsForm(IntPtr hwnd)
            : this()
        {
            m_HostedWindowHwnd = hwnd;

            txtTitle.Text = User32Windows.GetWindowText(m_HostedWindowHwnd, 255);
        }
        private void RefreshWindowsLists(List <DesktopWindow> runningWindows)
        {
            List <IntPtr> hwnds      = null;
            List <IntPtr> hwndsParam = null;

            if (!m_RefreshFull)
            {
                hwnds = (from w in m_RunningWindows
                         select w.Handle).ToList();
                hwndsParam = (from w in runningWindows
                              select w.Handle).ToList();
            }

            foreach (var window in runningWindows)
            {
                if (m_RefreshFull)
                {
                    if (m_RunningWindows.Contains(window))
                    {
                        continue;
                    }
                }
                else
                {
                    var index = hwnds.IndexOf(window.Handle);
                    if (index >= 0)
                    {
                        m_RunningWindows[index].Title = User32Windows.GetWindowText(window.Handle, 255);
                        continue;
                    }
                }

                m_RunningWindows.Add(window);
            }

            for (int i = 0; i < m_RunningWindows.Count; i++)
            {
                var window = m_RunningWindows[i];
                if (m_RefreshFull)
                {
                    if (!runningWindows.Contains(window))
                    {
                        m_RunningWindows.RemoveAt(i);
                        i--;
                    }
                }
                else
                {
                    if (!hwndsParam.Contains(window.Handle))
                    {
                        m_RunningWindows.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
示例#3
0
 private void DisplayTitle()
 {
     if (Hwnd != IntPtr.Zero)
     {
         lblTitle.Text = User32Windows.GetWindowText(Hwnd, 255);
     }
     else
     {
         lblTitle.Text = "-";
     }
 }
        private void GetWindowInfo()
        {
            m_HostedWindowHwnd = (IntPtr)int.Parse(txtHwnd.Text);

            StringBuilder title = new StringBuilder(255);

            if (User32Windows.IsWindow(m_HostedWindowHwnd))
            {
                User32Windows.GetWindowText(m_HostedWindowHwnd, title, title.Capacity + 1);
            }

            txtTitle.Text = title.ToString();
        }
示例#5
0
        private void InitializeAdditionalComponents()
        {
            // The panel for moving the form by any point.

            this.panel1 = new TransparentDraggablePanel(this)
            {
                Name     = "panel1",
                Location = new System.Drawing.Point(0, 0),
                Size     = this.Size,
                TabIndex = 1,
                Locked   = m_Locked
            };

            var title = User32Windows.GetWindowText(m_Handle, 255);

            this.Text = "Transparent - " + title;

            var icon = User32Windows.GetIcon(m_Handle);

            if (icon != null)
            {
                this.pictureBox1.Image = icon.ToBitmap();
            }

            this.Controls.Add(this.panel1);

            panel1.BringToFront();

            if (IsWindows10())
            {
                this.panel1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseWheel);
            }
            else
            {
                this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseWheel);
            }

            this.panel1.DoubleClick += new System.EventHandler(this.TransparentWindowToolForm_DoubleClick);
            this.panel1.MouseClick  += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseClick);
            this.LocationChanged    += (sender, e) =>
            {
                m_ClicksCount = ClicksToShow - 2;
            };
        }
        public TrackWindowTitleForm(IntPtr?hwnd                = null,
                                    Func <string> info         = null,
                                    Size?size                  = null,
                                    ContentAlignment alignment = ContentAlignment.MiddleLeft,
                                    int refreshInterval        = 1000)
        {
            InitializeComponent();

            m_Properties.BackColor   = this.BackColor;
            m_Properties.ForeColor   = this.ForeColor;
            m_Properties.BorderColor = Color.FromArgb(128, 255, 128);
            m_Properties.Font        = this.label1.Font;
            m_Properties.Height      = this.Height;
            m_Properties.Width       = this.Width;
            m_Properties.BorderWidth = 1;
            m_Properties.Interval    = 1;

            m_Hwnd = hwnd ?? IntPtr.Zero;

            if (hwnd != null)
            {
                info = () => User32Windows.GetWindowText(m_Hwnd, 255);
            }
            if (info != null)
            {
                this.m_Info = info;
            }

            m_FormSize = size ?? Size.Empty;
            if (size != null)
            {
                m_Properties.Width  = m_FormSize.Width;
                m_Properties.Height = m_FormSize.Height;
            }

            m_InfoTextAlign   = alignment;
            m_RefreshInterval = refreshInterval;

            InitializeAdditionalComponents();
        }
示例#7
0
        private void StartTracking()
        {
            if (Hwnd == IntPtr.Zero || !User32Windows.IsWindow(Hwnd))
            {
                MessageBox.Show("No window is selected.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            m_StartTime    = DateTime.Now;
            m_WindowIsHung = IsHungAppWindow(m_Hwnd) || m_TrackModalWindow;

            var msg = "• Start tracking"
                      + " [" + Hwnd.ToString() + "] \"" + User32Windows.GetWindowText(Hwnd, 255) + "\""
                      + "\r\n" + FormatTime(m_StartTime)
                      + " the program is " + (m_WindowIsHung ? "hung" : "accessible") + ".";

            Log(msg);
            WindowColors();

            chkTrackModalWindow.Enabled = false;

            timer1.Start();
        }
示例#8
0
        public SendCommandToolForm(IntPtr hwnd, string commands)
        {
            InitializeComponent();

            var refreshIntervalStr = ConfigurationManager.AppSettings.Get("CommandToolRefreshInterval");

            this.timer1.Interval = int.Parse(refreshIntervalStr);

            m_HostWindowHwnd = hwnd;
            m_Commands       = commands;

            StringBuilder title = new StringBuilder(255);

            try
            {
                User32Windows.GetWindowText(m_HostWindowHwnd, title, title.Capacity + 1);
                m_HostWindowTitle = title.ToString();
            }
            catch { }

            Text = "Send Command - " + title.ToString();

            toolTip1.SetToolTip(this, Text);
        }
示例#9
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();
                }
            }
        }