private void PicIcon_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (e.Clicks == 1)
         {
             var pt = picIcon.Location;
             pt.Y = picIcon.Bottom;
             pt   = PointToScreen(pt);
             var dispRect = RECT.FromRectangle(ClientRectangle);
             var hMenu    = NativeMethods.GetSystemMenu(Handle, false);
             NativeMethods.TrackPopupMenu(hMenu, NativeConstants.TPM_LEFTBUTTON, pt.X, pt.Y, 0, Handle, ref dispRect);
         }
         else
         {
             Close();
         }
     }
     else if (e.Button == MouseButtons.Right)
     {
         var mouseScreen = MousePosition;
         var dispRect    = RECT.FromRectangle(ClientRectangle);
         var hMenu       = NativeMethods.GetSystemMenu(Handle, false);
         NativeMethods.TrackPopupMenu(hMenu, NativeConstants.TPM_LEFTBUTTON, mouseScreen.X, mouseScreen.Y, 0, Handle, ref dispRect);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the background image defined by the visual style for the specified control part
        /// </summary>
        /// <param name="g">The Graphics to draw on</param>
        /// <param name="windowClass">The class of the part to draw</param>
        /// <param name="part">The part to draw</param>
        /// <param name="partState">The state of the part to draw</param>
        /// <param name="drawRect">The Rectangle in which the part is drawn</param>
        /// <param name="clipRect">The Rectangle that represents the clipping area for the part</param>
        public static void DrawThemeBackground(Graphics g, string windowClass, int part, int partState, Rectangle drawRect, Rectangle clipRect)
        {
            if (g == null || drawRect.Width <= 0 || drawRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0)
            {
                return;
            }

            // open theme data
            IntPtr hTheme = IntPtr.Zero;

            hTheme = NativeMethods.OpenThemeData(hTheme, windowClass);

            // make sure we have a valid handle
            if (hTheme != IntPtr.Zero)
            {
                // get a graphics object the UxTheme can draw into
                IntPtr hdc = g.GetHdc();

                // get the draw and clipping rectangles
                RECT dRect = RECT.FromRectangle(drawRect);
                RECT cRect = RECT.FromRectangle(clipRect);

                // draw the themed background
                NativeMethods.DrawThemeBackground(hTheme, hdc, part, partState, ref dRect, ref cRect);

                // clean up resources
                g.ReleaseHdc(hdc);
            }

            // close the theme handle
            NativeMethods.CloseThemeData(hTheme);
        }
Ejemplo n.º 3
0
        private void outlineResized(FrameForm target)
        {
            Rectangle rectangle = currentWindow.Rectangle.ToRectangle();
            Rectangle position  = currentWindow.Position.ToRectangle();
            Point     p         = new Point(target.Left - rectangle.Left + position.Left,
                                            target.Top - rectangle.Top + position.Top);
            Rectangle newPos = new Rectangle(p, target.Size);

            currentWindow.Position = RECT.FromRectangle(newPos);
        }
Ejemplo n.º 4
0
        private void positionYToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int where = int.Parse((string)((ToolStripMenuItem)sender).Tag);
            Rectangle pos      = currentWindow.Position.ToRectangle();
            Rectangle outer    = Screen.FromRectangle(pos).WorkingArea;
            int       spacingY = outer.Height - pos.Height;

            pos.Y = spacingY * where / 2 + outer.Y;
            currentWindow.Position = RECT.FromRectangle(pos);
            UpdateControls();
        }
Ejemplo n.º 5
0
        private void sizeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string[]  tmp = ((string)((ToolStripMenuItem)sender).Tag).Split('x');
            int       ww  = int.Parse(tmp[0]);
            int       hh  = int.Parse(tmp[1]);
            Rectangle pos = currentWindow.Position.ToRectangle();

            pos.Size = new Size(ww, hh);
            currentWindow.Position = RECT.FromRectangle(pos);
            UpdateControls();
        }
Ejemplo n.º 6
0
 private void resizeDrag_MouseMove(object sender, MouseEventArgs e)
 {
     if (sizeDragging)
     {
         Rectangle pos = currentWindow.Position.ToRectangle();
         pos.Size = new Size(pos.Size.Width + e.X - posX, pos.Size.Height + e.Y - posY);
         currentWindow.Position = RECT.FromRectangle(pos);
         posX = e.X;
         posY = e.Y;
         UpdateControls();
     }
 }
Ejemplo n.º 7
0
 private void positionDrag_MouseMove(object sender, MouseEventArgs e)
 {
     if (positionDragging)
     {
         Rectangle pos = currentWindow.Position.ToRectangle();
         pos.Location           = new Point(pos.Location.X + e.X - posX, pos.Location.Y + e.Y - posY);
         currentWindow.Position = RECT.FromRectangle(pos);
         posX = e.X;
         posY = e.Y;
         UpdateControls();
     }
 }
Ejemplo n.º 8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            var region = this.DetermineNcRegion(e.Location, FrameBorderSize.Width, FrameBorderSize.Height, CaptionMargin);

            if (region != NativeConstants.HTCLIENT)
            {
                if (WindowState != FormWindowState.Maximized)
                {
                    MouseButtonAction action;
                    if (e.Button == MouseButtons.Left)
                    {
                        action = MouseButtonAction.LeftButtonDown;
                    }
                    else if (e.Button == MouseButtons.Right)
                    {
                        action = MouseButtonAction.RightButtonDown;
                    }
                    else
                    {
                        return;
                    }
                    this.NcHitTest(e.Location, action, FrameBorderSize.Width, FrameBorderSize.Height, CaptionMargin);
                }
            }
            if (e.Button == MouseButtons.Right && e.Y <= lblCaption.Bottom)
            {
                var mousePosition = MousePosition;
                var displayRect   = RECT.FromRectangle(DisplayRectangle);
                var hMenu         = NativeMethods.GetSystemMenu(Handle, false);
                NativeMethods.TrackPopupMenu(hMenu, NativeConstants.TPM_LEFTBUTTON, mousePosition.X, mousePosition.Y, 0, Handle, ref displayRect);
            }
            if (e.Clicks == 2)
            {
                MouseButtonAction action;
                if (e.Button == MouseButtons.Left)
                {
                    action = MouseButtonAction.LeftButtonDoubleClick;
                }
                else if (e.Button == MouseButtons.Right)
                {
                    action = MouseButtonAction.RightButtonDoubleClick;
                }
                else
                {
                    return;
                }
                this.NcHitTest(e.Location, action, FrameBorderSize.Width, FrameBorderSize.Height, CaptionMargin);
            }
        }
Ejemplo n.º 9
0
        public static void DrawFocusRect(Graphics g, Rectangle rect)
        {
            IntPtr hdc = IntPtr.Zero;
            RECT   r;

            try
            {
                r   = RECT.FromRectangle(rect);
                hdc = g.GetHdc();
                DrawFocusRect(hdc, ref r);
            }
            finally
            {
                if (hdc != IntPtr.Zero)
                {
                    g.ReleaseHdc(hdc);
                    hdc = IntPtr.Zero;
                }
            }
        }
Ejemplo n.º 10
0
        private void size_Click(object sender, EventArgs e)
        {
            int       ww, hh;
            Rectangle pos   = currentWindow.Position.ToRectangle();
            string    width = InputBox.Show(ParentForm, "Width:", "" + pos.Width);

            if (width == null || !int.TryParse(width, out ww))
            {
                return;
            }
            string height = InputBox.Show(ParentForm, "Height:", "" + pos.Height);

            if (height == null || !int.TryParse(height, out hh))
            {
                return;
            }
            pos.Size = new Size(ww, hh);
            currentWindow.Position = RECT.FromRectangle(pos);
            UpdateControls();
        }
Ejemplo n.º 11
0
        private void align(SystemWindow fg)
        {
            if (!fg.Visible)
            {
                MessageBox.Show("Window is not visible!", "NeatKeys");
                return;
            }
            if (!fg.Enabled)
            {
                MessageBox.Show("Window is disabled!", "NeatKeys");
                return;
            }
            if (!fg.Movable)
            {
                MessageBox.Show("Window is not movable!", "NeatKeys");
                return;
            }
            if (!fg.Resizable)
            {
                MessageBox.Show("Window is not resizable!", "NeatKeys");
                return;
            }
            if (fg.WindowState != FormWindowState.Normal)
            {
                MessageBox.Show("Window is minimized or maximized!", "NeatKeys");
                return;
            }
            Rectangle wa = Screen.FromHandle(fg.HWnd).WorkingArea;
            Rectangle r  = fg.Position.ToRectangle();

            r.Offset(-wa.X, -wa.Y);
            int dx = wa.Width / 12;
            int dy = wa.Height / 12;
            int nx = ((r.X * 24 + wa.Width) / (wa.Width * 2)) * wa.Width / 12;
            int nw = ((r.Width * 24 + wa.Width) / (wa.Width * 2)) * wa.Width / 12;
            int ny = ((r.Y * 24 + wa.Height) / (wa.Height * 2)) * wa.Height / 12;
            int nh = ((r.Height * 24 + wa.Height) / (wa.Height * 2)) * wa.Height / 12;

            r           = new Rectangle(nx, ny, nw, nh);
            fg.Position = RECT.FromRectangle(r);
        }
Ejemplo n.º 12
0
        private void position_Click(object sender, EventArgs e)
        {
            int       xx, yy;
            Rectangle pos  = currentWindow.Position.ToRectangle();
            string    left = InputBox.Show(ParentForm, "Left:", "" + pos.Left);

            if (left == null || !int.TryParse(left, out xx))
            {
                return;
            }
            string top = InputBox.Show(ParentForm, "Top:", "" + pos.Top);

            if (top == null || !int.TryParse(top, out yy))
            {
                return;
            }
            pos.Location = new Point(xx, yy);

            currentWindow.Position = RECT.FromRectangle(pos);
            UpdateControls();
        }
Ejemplo n.º 13
0
        public void DoResize(int factor, int x, int y, int w, int h, bool hide)
        {
            if (!fgWindow.Movable || !fgWindow.Enabled || !fgWindow.Visible)
            {
                return;
            }
            Rectangle r;
            Rectangle wa  = Screen.AllScreens[currentScreen].WorkingArea;
            Rectangle fgp = adjustment.BaseRect;

            if (factor == 0)
            {
                r = new Rectangle(x, y, w, h);
            }
            else if (factor == -1)
            {
                r = new Rectangle(fgp.X, fgp.Y, fgp.Width, fgp.Height);
            }
            else
            {
                int xx, yy, ww, hh;
                if (x == -1)
                {
                    xx = fgp.X;
                    ww = fgp.Width;
                }
                else
                {
                    xx = wa.Width * x / factor;
                    ww = wa.Width * w / factor;
                }
                if (y == -1)
                {
                    yy = fgp.Y;
                    hh = fgp.Height;
                }
                else
                {
                    yy = wa.Height * y / factor;
                    hh = wa.Height * h / factor;
                }
                r = new Rectangle(xx, yy, ww, hh);
            }
            r.Offset(wa.Location);
            r = adjustment.adjust(r);
            if (!fgWindow.Resizable)
            {
                if (r.Width != fgp.Width || r.Height != fgp.Height)
                {
                    r.X     += (r.Width - fgp.Width) / 2;
                    r.Y     += (r.Height - fgp.Height) / 2;
                    r.Width  = fgp.Width;
                    r.Height = fgp.Height;
                }
            }
            Visible = false;
            FormWindowState oldws = fgWindow.WindowState;

            fgWindow.WindowState = FormWindowState.Normal;
            fgWindow.Position    = RECT.FromRectangle(r);
            fgWindow.WindowState = oldws;
            if (hide)
            {
                SystemWindow.ForegroundWindow = fgWindow;
            }
            else
            {
                Visible = true;
            }
        }
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            int shiftState = shiftKey.AsyncState;
            int altState   = altKey.AsyncState;
            int ctrlState  = ctrlKey.AsyncState;

            if (menuMode != 0)
            {
                switch (menuMode)
                {
                case 1:     // in menu
                {
                    if (ctrlState >= 0)
                    {
                        menuMode          = 0;
                        menuPanel.Visible = false;
                    }
                    else if (shiftState < 0)
                    {
                        InvokeMenu(menuIndex);
                        return;
                    }
                    else
                    {
                        if (MousePosition.X / 5 > lastX && menuIndex % 3 != 2)
                        {
                            menuIndex++;
                        }
                        if (MousePosition.X / 5 < lastX && menuIndex % 3 != 0)
                        {
                            menuIndex--;
                        }
                        if (MousePosition.Y / 5 > lastY && menuIndex < 6)
                        {
                            menuIndex += 3;
                        }
                        if (MousePosition.Y / 5 < lastY && menuIndex >= 3)
                        {
                            menuIndex -= 3;
                        }
                        menuButtons[menuIndex].Select();
                    }
                    lastX = MousePosition.X / 5;
                    lastY = MousePosition.Y / 5;
                }
                break;

                case 2:     // move/resize
                    if (shiftState >= 0)
                    {
                        infoPanel.Visible = false;
                        menuMode          = 1;
                        lastX             = MousePosition.X / 5;
                        lastY             = MousePosition.Y / 5;
                    }
                    else
                    {
                        Rectangle r = windowData.Window.Position.ToRectangle();
                        if (menuIndex == 0)
                        {
                            r.Location = new Point(MousePosition.X + lastX, MousePosition.Y + lastY);
                        }
                        else
                        {
                            r.Size = new Size(MousePosition.X + lastX, MousePosition.Y + lastY);
                        }
                        windowData.Window.Position = RECT.FromRectangle(r);
                    }
                    break;

                case 3:     // select
                    if (shiftState >= 0)
                    {
                        if (menuListBox.Focused && menuListBox.Items.Count > 0)
                        {
                            switch (menuIndex)
                            {
                            case 1:         // Toggle enabled
                                windowData.Window.Enabled = menuListBox.SelectedIndex == 0;
                                break;

                            case 2:         // Toggle visible
                                windowData.Window.VisibilityFlag = menuListBox.SelectedIndex == 0;
                                break;

                            case 3:         // Select Parent or Ancestor
                                goto case 5;

                            case 5:         // Select Child
                                SystemWindow sw = (SystemWindow)menuListBox.SelectedItem;
                                if (sw != null)
                                {
                                    UpdateProperties(sw);
                                }
                                break;

                            case 6:         // Advanced
                                // unused
                                break;
                            }
                        }
                        listPanel.Visible = false;
                        menuMode          = 1;
                    }
                    else
                    {
                        if (menuListBox.Focused && menuListBox.Items.Count > 0)
                        {
                            if (MousePosition.Y / 5 > lastY)
                            {
                                menuListBox.SelectedIndex = (menuListBox.SelectedIndex + 1) % menuListBox.Items.Count;
                            }
                            if (MousePosition.Y / 5 < lastY)
                            {
                                menuListBox.SelectedIndex = (menuListBox.SelectedIndex + menuListBox.Items.Count) % menuListBox.Items.Count;
                            }
                        }
                        if (MousePosition.X / 5 > lastX)
                        {
                            menuListBox.Focus();
                        }
                        if (MousePosition.X / 5 < lastX)
                        {
                            menuCancel.Focus();
                        }
                    }
                    lastX = MousePosition.X / 5;
                    lastY = MousePosition.Y / 5;
                    break;

                case 4:     // Change/Scroll Tab
                    if (shiftState >= 0)
                    {
                        menuPanel.Visible = true;
                        menuMode          = 1;
                    }
                    else
                    {
                        if (tabs.SelectedIndex <= 1)
                        {
                            TextBox tb = tabs.SelectedIndex == 1 ? parentProperties : windowProperties;
                            if (MousePosition.Y / 5 > lastY)
                            {
                                int pos = tb.SelectionStart;
                                pos = tb.Text.IndexOf('\n', pos);
                                if (pos == -1)
                                {
                                    tb.Select(tb.Text.Length, 0);
                                }
                                else
                                {
                                    tb.Select(pos + 1, 0);
                                }
                                tb.ScrollToCaret();
                            }
                            if (MousePosition.Y / 5 < lastY)
                            {
                                int pos = tb.SelectionStart;
                                pos = tb.Text.LastIndexOf("\n", pos);
                                if (pos == -1)
                                {
                                    tb.Select(0, 0);
                                }
                                else
                                {
                                    tb.Select(pos - 2, 0);
                                }
                                tb.ScrollToCaret();
                            }
                        }

                        if (MousePosition.X / 5 > lastX)
                        {
                            tabs.SelectedIndex = 1;
                        }
                        if (MousePosition.X / 5 < lastX)
                        {
                            tabs.SelectedIndex = 0;
                        }
                    }
                    lastX = MousePosition.X / 5;
                    lastY = MousePosition.Y / 5;
                    break;

                default:
                    break;
                }
                return;
            }
            if (ctrlMenu.Checked && ctrlState < 0)
            {
                menuPanel.Visible = true;
                menuMode          = 1;
                menuIndex         = 4;
                menuButtons[4].Select();
                lastX = MousePosition.X / 5;
                lastY = MousePosition.Y / 5;
                Text  = "Window Information (Menu)";
                return;
            }
            if (altState < 0 && altToggleTab.Checked)
            {
                altToggle          = true;
                tabs.SelectedIndex = 1;
            }
            else if (altToggle)
            {
                altToggle          = false;
                tabs.SelectedIndex = 0;
            }
            if (MousePosition.X != lastX || MousePosition.Y != lastY)
            {
                delaycount = 50;
                delay.Text = "Delay";
                lastX      = MousePosition.X;
                lastY      = MousePosition.Y;
                if (avoidMouse.Checked && shiftState >= 0)
                {
                    if (lastX >= Left && lastY >= Top && lastX <= Left + Width && lastY <= Top + Height)
                    {
                        Screen cs = Screen.FromPoint(Location);
                        int    ll = cs.WorkingArea.Width - (Left + Width - cs.WorkingArea.X) + cs.WorkingArea.X;
                        int    tt = cs.WorkingArea.Height - (Top + Height - cs.WorkingArea.Y) + cs.WorkingArea.Y;
                        Location = new Point(ll, tt);
                        if (lastX >= Left && lastY >= Top && lastX <= Left + Width && lastY <= Top + Height)
                        {
                            Location = new Point(5, 5);
                        }
                    }
                }
                SystemWindow sw = SystemWindow.FromPointEx(lastX, lastY, false, false);
                UpdateProperties(sw);
                if (tabs.SelectedIndex == 1)
                {
                    this.Text = "Window Information (Relative: " + (lastX - copiedX) + "," + (lastY - copiedY) + ")";
                }
                else
                {
                    this.Text = "Window Information (Mouse: " + lastX + "," + lastY + ")";
                }
            }
            else
            {
                if (delaycount > 0)
                {
                    delaycount--;
                    if (delaycount < 40)
                    {
                        delay.Text = "" + delaycount / 10;
                    }
                    if (delaycount < 10)
                    {
                        delaycount = -1;
                        if (delayedUpdate.Checked)
                        {
                            windowProperties.Text = delayedProperties;
                            parentProperties.Text = delayedMainProperties;
                        }
                        if (autoCopy.Checked)
                        {
                            copied.Items.Insert(1, new CopiedWindow(windowData, windowProperties.Text, parentData, parentProperties.Text));
                            delay.Text = "Copied";
                        }
                        else
                        {
                            delay.Text = "Delay";
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public static bool ValidateRect(IntPtr hWnd, System.Drawing.Rectangle rectangle)
        {
            RECT rect = RECT.FromRectangle(rectangle);

            return(ValidateRect(hWnd, ref rect));
        }
Ejemplo n.º 16
0
        public static bool InvalidateRect(IntPtr hWnd, System.Drawing.Rectangle rectangle, bool bErase)
        {
            RECT rect = RECT.FromRectangle(rectangle);

            return(InvalidateRect(hWnd, ref rect, bErase));
        }
Ejemplo n.º 17
0
 public static void DrawText(IDeviceContext dc, String text, Rectangle bounds, TextFormatFlags format)
 {
     try
     {
         var options = new DTTOPTS();
         NativeMethods.DrawThemeTextEx(Renderer.Handle, dc.GetHdc(), 0, 0, text, text.Length, format, RECT.FromRectangle(bounds), options);
     }
     finally
     {
         dc.ReleaseHdc();
     }
 }