示例#1
0
文件: Snap.cs 项目: sysr-q/xcap
        public Snap()
        {
            /// Setup default keybinds.
            RegistryKey key_snap = Registry.CurrentUser.CreateSubKey(@"Software\xcap");
            if (key_snap.GetValue("SNAP") == null)
                key_snap.SetValue("SNAP", "+--~");
            if (key_snap.GetValue("FULL") == null)
                key_snap.SetValue("FULL", "+-+~");
            if (key_snap.GetValue("URI") == null)
                key_snap.SetValue("URI", Settings.ServerUrl.ToString());
            if (key_snap.GetValue("OWN_SERV") == null)
                key_snap.SetValue("OWN_SERV", Settings.UseOwnServer);

            form = new DummyForm();
            form1 = new DummyForm1();

            Settings.RefreshKeyBinds();
            GenerateIconList();

            icon = new NotifyIcon();
            icon.Text = "xcap";
            icon.Icon = form.Icon;
            icon.Visible = true;
            icon.ContextMenu = new ContextMenu();

            MenuItem options = new MenuItem("Options");
            options.Click += (sender, e) =>
            {
                new Options().Show();
            };
            icon.ContextMenu.MenuItems.Add(options);

            icon.ContextMenu.MenuItems.Add("Exit", (sender, e) =>
            {
                Application.Exit();
            });

            icon.DoubleClick += (sender, e) =>
            {
                Take();
            };
            Application.Run();

            form.Dispose();
            form1.Dispose();
            Settings.ghk_Snap.Unregister();
            Settings.ghk_Full.Unregister();

            icon.Visible = false;
            icon.Dispose();
        }
示例#2
0
文件: Snap.cs 项目: sysr-q/xcap
        public static void Take()
        {
            Form SelectFrm = new DummyForm();
            SelectFrm.Cursor = Cursors.Cross;
            /// Make sure that the form will use the *entire* screen bounds, or else it might shrink due to window tiling.
            SelectFrm.MaximumSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            SelectFrm.WindowState = FormWindowState.Maximized;
            SelectFrm.FormBorderStyle = FormBorderStyle.None;
            SelectFrm.ShowInTaskbar = false;
            SelectFrm.Opacity = Settings.Frozen ? 1.0 : 0.5;
            SelectFrm.BackColor = Color.White;
            SelectFrm.TopMost = true;

            Bitmap bm = null;
            if (Settings.Frozen)
            {
                bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                Graphics snapShot = Graphics.FromImage(bm);
                snapShot.CopyFromScreen(0, 0,
                    Screen.PrimaryScreen.Bounds.X,
                    Screen.PrimaryScreen.Bounds.Y,
                    Screen.PrimaryScreen.Bounds.Size,
                    CopyPixelOperation.SourceCopy);
                bm = bm.Clone(new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height), PixelFormat.Format32bppArgb);
                SelectFrm.BackgroundImage = bm;
            }
            SelectFrm.Paint += (sender, e) =>
            {
                mousePos = (down) ? Cursor.Position : upPos;
                where wh = GetWhere();

                selectedRect = new Rectangle(Math.Min(downPos.X, mousePos.X),
                    Math.Min(downPos.Y, mousePos.Y),
                    Math.Abs(downPos.X - mousePos.X),
                    Math.Abs(downPos.Y - mousePos.Y));

                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Gray)), selectedRect);
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0x00, 0x00, 0x00), 1), selectedRect);

                if (Settings.Frozen)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Gray)),
                        new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
                    );
                }

                String info = selectedRect.Width + "\n" + selectedRect.Height;
                SizeF sizef = e.Graphics.MeasureString(info, new Font("Arial", 8));
                PointF point = PointFromWhere(wh, sizef);

                e.Graphics.DrawString(info, new Font("Arial", 8), new SolidBrush(Color.Black),
                    point);
            };
            SelectFrm.MouseDown += (sender, e) =>
            {
                SelectFrm.Invalidate();
                down = true;
                downPos = new Point(e.X, e.Y);
            };
            SelectFrm.MouseMove += (sender, e) =>
            {
                if (down)
                {
                    SelectFrm.Invalidate();
                }
            };
            SelectFrm.MouseUp += (sender, e) =>
            {
                down = false;
                upPos = new Point(e.X, e.Y);
                if (e.Button == MouseButtons.Right)
                {
                    SelectFrm.DialogResult = DialogResult.Cancel;
                }
                else if (e.Button == MouseButtons.Left)
                {
                    SelectFrm.DialogResult = DialogResult.OK;
                }
            };

            if (SelectFrm.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                        Screen.PrimaryScreen.Bounds.Height,
                        PixelFormat.Format32bppArgb);

                    Graphics snapShot = Graphics.FromImage(bitmap);

                    snapShot.CopyFromScreen(0, 0,
                        Screen.PrimaryScreen.Bounds.X,
                        Screen.PrimaryScreen.Bounds.Y,
                        Screen.PrimaryScreen.Bounds.Size,
                        CopyPixelOperation.SourceCopy);

                    if (bm != null)
                    {
                        bitmap = bm.Clone(selectedRect, PixelFormat.Format32bppArgb);
                    }
                    else
                    {
                        bitmap = bitmap.Clone(selectedRect, PixelFormat.Format32bppArgb);
                    }
                    Upload(bitmap);
                    bitmap.Dispose();
                    snapShot.Dispose();
                    SelectFrm.Dispose();
                }
                catch (Exception ex)
                {
                    LogError(ex);
                    MessageBox.Show(string.Format("An error occured!\n"
                    + "Please send the contents of your error.log to the developer."), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (!SelectFrm.IsDisposed)
                SelectFrm.Dispose();
            CleanUp();
        }
示例#3
0
        public Snap()
        {
            /// Setup default keybinds.
            RegistryKey key_snap = Registry.CurrentUser.CreateSubKey(@"Software\xcap");

            if (key_snap.GetValue("SNAP") == null)
            {
                key_snap.SetValue("SNAP", "+--~");
            }
            if (key_snap.GetValue("FULL") == null)
            {
                key_snap.SetValue("FULL", "+-+~");
            }
            if (key_snap.GetValue("URI") == null)
            {
                key_snap.SetValue("URI", Settings.ServerUrl.ToString());
            }
            if (key_snap.GetValue("OWN_SERV") == null)
            {
                key_snap.SetValue("OWN_SERV", Settings.UseOwnServer);
            }

            form  = new DummyForm();
            form1 = new DummyForm1();

            Settings.RefreshKeyBinds();
            GenerateIconList();

            icon             = new NotifyIcon();
            icon.Text        = "xcap";
            icon.Icon        = form.Icon;
            icon.Visible     = true;
            icon.ContextMenu = new ContextMenu();

            MenuItem options = new MenuItem("Options");

            options.Click += (sender, e) =>
            {
                new Options().Show();
            };
            icon.ContextMenu.MenuItems.Add(options);

            icon.ContextMenu.MenuItems.Add("Exit", (sender, e) =>
            {
                Application.Exit();
            });

            icon.DoubleClick += (sender, e) =>
            {
                Take();
            };
            Application.Run();

            form.Dispose();
            form1.Dispose();
            Settings.ghk_Snap.Unregister();
            Settings.ghk_Full.Unregister();

            icon.Visible = false;
            icon.Dispose();
        }
示例#4
0
        public static void Take()
        {
            Form SelectFrm = new DummyForm();

            SelectFrm.Cursor = Cursors.Cross;
            /// Make sure that the form will use the *entire* screen bounds, or else it might shrink due to window tiling.
            SelectFrm.MaximumSize     = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            SelectFrm.WindowState     = FormWindowState.Maximized;
            SelectFrm.FormBorderStyle = FormBorderStyle.None;
            SelectFrm.ShowInTaskbar   = false;
            SelectFrm.Opacity         = Settings.Frozen ? 1.0 : 0.5;
            SelectFrm.BackColor       = Color.White;
            SelectFrm.TopMost         = true;

            Bitmap bm = null;

            if (Settings.Frozen)
            {
                bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                Graphics snapShot = Graphics.FromImage(bm);
                snapShot.CopyFromScreen(0, 0,
                                        Screen.PrimaryScreen.Bounds.X,
                                        Screen.PrimaryScreen.Bounds.Y,
                                        Screen.PrimaryScreen.Bounds.Size,
                                        CopyPixelOperation.SourceCopy);
                bm = bm.Clone(new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height), PixelFormat.Format32bppArgb);
                SelectFrm.BackgroundImage = bm;
            }
            SelectFrm.Paint += (sender, e) =>
            {
                mousePos = (down) ? Cursor.Position : upPos;
                where wh = GetWhere();

                selectedRect = new Rectangle(Math.Min(downPos.X, mousePos.X),
                                             Math.Min(downPos.Y, mousePos.Y),
                                             Math.Abs(downPos.X - mousePos.X),
                                             Math.Abs(downPos.Y - mousePos.Y));

                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Gray)), selectedRect);
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0x00, 0x00, 0x00), 1), selectedRect);

                if (Settings.Frozen)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Gray)),
                                             new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
                                             );
                }

                String info  = selectedRect.Width + "\n" + selectedRect.Height;
                SizeF  sizef = e.Graphics.MeasureString(info, new Font("Arial", 8));
                PointF point = PointFromWhere(wh, sizef);

                e.Graphics.DrawString(info, new Font("Arial", 8), new SolidBrush(Color.Black),
                                      point);
            };
            SelectFrm.MouseDown += (sender, e) =>
            {
                SelectFrm.Invalidate();
                down    = true;
                downPos = new Point(e.X, e.Y);
            };
            SelectFrm.MouseMove += (sender, e) =>
            {
                if (down)
                {
                    SelectFrm.Invalidate();
                }
            };
            SelectFrm.MouseUp += (sender, e) =>
            {
                down  = false;
                upPos = new Point(e.X, e.Y);
                if (e.Button == MouseButtons.Right)
                {
                    SelectFrm.DialogResult = DialogResult.Cancel;
                }
                else if (e.Button == MouseButtons.Left)
                {
                    SelectFrm.DialogResult = DialogResult.OK;
                }
            };

            if (SelectFrm.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                               Screen.PrimaryScreen.Bounds.Height,
                                               PixelFormat.Format32bppArgb);

                    Graphics snapShot = Graphics.FromImage(bitmap);

                    snapShot.CopyFromScreen(0, 0,
                                            Screen.PrimaryScreen.Bounds.X,
                                            Screen.PrimaryScreen.Bounds.Y,
                                            Screen.PrimaryScreen.Bounds.Size,
                                            CopyPixelOperation.SourceCopy);

                    if (bm != null)
                    {
                        bitmap = bm.Clone(selectedRect, PixelFormat.Format32bppArgb);
                    }
                    else
                    {
                        bitmap = bitmap.Clone(selectedRect, PixelFormat.Format32bppArgb);
                    }
                    Upload(bitmap);
                    bitmap.Dispose();
                    snapShot.Dispose();
                    SelectFrm.Dispose();
                }
                catch (Exception ex)
                {
                    LogError(ex);
                    MessageBox.Show(string.Format("An error occured!\n"
                                                  + "Please send the contents of your error.log to the developer."), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (!SelectFrm.IsDisposed)
            {
                SelectFrm.Dispose();
            }
            CleanUp();
        }