Ejemplo n.º 1
0
        private void CaptureOptions_Load(object sender, EventArgs e)
        {
            WindowDropdown.Items.Clear();
            WindowHandle = IntPtr.Zero;

            ExternalAPI.EnumWindows(new ExternalAPI.EnumWindowsProc(EnumWindowsCallback), IntPtr.Zero);

            foreach (WindowData Data in WindowDropdown.Items)
            {
                if (Data.Name.Equals(WindowName, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (MatchTitle)
                    {
                        if (Data.Title != WindowTitle)
                        {
                            continue;
                        }
                    }

                    WindowDropdown.SelectedItem = Data;
                    break;
                }
            }

            MatchTitleCheck.Checked  = MatchTitle;
            TopmostOnlyCheck.Checked = TopmostOnly;

            MethodDropdown.SelectedIndex = (int)Method;
        }
Ejemplo n.º 2
0
        public static Bitmap CaptureWindow(IntPtr hWnd, CaptureMethod Method)
        {
            if (hWnd == IntPtr.Zero)
            {
                return(null);
            }

            int style = ExternalAPI.GetWindowLong(hWnd, -16);

            //int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

            // Ignore Popup windows
            if ((style & 0x80000000) != 0)
            {
                return(null);
            }

            var winrect = new ExternalAPI.Rect();

            ExternalAPI.GetWindowRect(hWnd, ref winrect);

            var clientrec = new ExternalAPI.Rect();

            ExternalAPI.GetClientRect(hWnd, ref clientrec);

            int width  = clientrec.right - clientrec.left;
            int height = clientrec.bottom - clientrec.top;

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(bmp))
            {
                if (Method == CaptureMethod.PaintWindow)
                {
                    IntPtr Handle = graphics.GetHdc();

                    ExternalAPI.PrintWindow(hWnd, Handle, 1);

                    graphics.ReleaseHdc(Handle);
                }
                else if (Method == CaptureMethod.DesktopCapture)
                {
                    var tempPoint = new Point();
                    tempPoint.x = clientrec.left;
                    tempPoint.y = clientrec.top;
                    ClientToScreen(hWnd, ref tempPoint);

                    graphics.CopyFromScreen(tempPoint.x, tempPoint.y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
                }
            }

            return(bmp);
        }
Ejemplo n.º 3
0
        private bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
        {
            int style   = ExternalAPI.GetWindowLong(hWnd, -16);
            int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

            if (!ExternalAPI.IsWindowVisible(hWnd))
            {
                return(true);
            }

            // Ignore Popup windows
            if ((style & 0x80000000) != 0)
            {
                return(true);
            }

            uint          ProcessID;
            StringBuilder TempString = new StringBuilder();

            ExternalAPI.GetWindowThreadProcessId(hWnd, out ProcessID);

            IntPtr ProcessHandle = ExternalAPI.OpenProcess(0x0400, false, ProcessID);

            TempString.EnsureCapacity(1024);
            ExternalAPI.GetModuleFileNameEx(ProcessHandle, IntPtr.Zero, TempString, TempString.Capacity);

            if (TempString.ToString() == System.Reflection.Assembly.GetExecutingAssembly().Location)
            {
                return(true);
            }

            WindowData Entry;

            Entry.Handle = hWnd;
            Entry.Name   = System.IO.Path.GetFileNameWithoutExtension(TempString.ToString());

            ExternalAPI.CloseHandle(ProcessHandle);

            int size = ExternalAPI.GetWindowTextLength(hWnd);

            if (size != 0)
            {
                TempString.EnsureCapacity(size + 1);
                ExternalAPI.GetWindowText(hWnd, TempString, TempString.Capacity);

                Entry.Title = TempString.ToString();
            }
            else
            {
                Entry.Title = "";
            }

            WindowDropdown.Items.Add(Entry);

            return(true);
        }
Ejemplo n.º 4
0
            public bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
            {
                int style   = ExternalAPI.GetWindowLong(hWnd, -16);
                int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

                if (!ExternalAPI.IsWindowVisible(hWnd))
                {
                    return(true);
                }

                // Ignore Popup windows
                if ((style & 0x80000000) != 0)
                {
                    return(true);
                }

                uint          ProcessID;
                StringBuilder TempString = new StringBuilder();

                ExternalAPI.GetWindowThreadProcessId(hWnd, out ProcessID);

                IntPtr ProcessHandle = ExternalAPI.OpenProcess(0x0400, false, ProcessID);

                TempString.EnsureCapacity(1024);
                ExternalAPI.GetModuleFileNameEx(ProcessHandle, IntPtr.Zero, TempString, TempString.Capacity);
                ExternalAPI.CloseHandle(ProcessHandle);

                string ExeName = System.IO.Path.GetFileNameWithoutExtension(TempString.ToString());

                if (Name.Equals(ExeName, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (MatchTitle)
                    {
                        int size = ExternalAPI.GetWindowTextLength(hWnd);
                        if (size != 0)
                        {
                            TempString.EnsureCapacity(size + 1);
                            ExternalAPI.GetWindowText(hWnd, TempString, TempString.Capacity);

                            if (TempString.ToString() == Title)
                            {
                                Handle = hWnd;
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        Handle = hWnd;
                        return(false);
                    }
                }

                return(true);
            }
Ejemplo n.º 5
0
        private IntPtr FindWindow(string ProcessName, string WindowTitle, bool MatchTitle)
        {
            FindProcessCallback.Name       = ProcessName;
            FindProcessCallback.Title      = WindowTitle;
            FindProcessCallback.MatchTitle = MatchTitle;

            FindProcessCallback.Handle = IntPtr.Zero;

            ExternalAPI.EnumWindows(new ExternalAPI.EnumWindowsProc(FindProcessCallback.EnumWindowsCallback), IntPtr.Zero);

            return(FindProcessCallback.Handle);
        }
Ejemplo n.º 6
0
        private void SaveSettings()
        {
            ExternalAPI.WritePrivateProfileString("Capture", "Name", WindowName, SettingsFile);
            ExternalAPI.WritePrivateProfileString("Capture", "Title", WindowTitle, SettingsFile);
            ExternalAPI.WritePrivateProfileString("Capture", "Match Title", MatchWindowTitle.ToString(), SettingsFile);
            ExternalAPI.WritePrivateProfileString("Capture", "Topmost Only", TopmostOnly.ToString(), SettingsFile);
            ExternalAPI.WritePrivateProfileString("Capture", "Capture Method", Method.ToString(), SettingsFile);

            ExternalAPI.WritePrivateProfileString("Settings", "Resize Output", ResizeOutput.ToString(), SettingsFile);
            ExternalAPI.WritePrivateProfileString("Settings", "Output Size", string.Format("{0}, {1}", ResizeOutputWidth, ResizeOutputHeight), SettingsFile);
            ExternalAPI.WritePrivateProfileString("Settings", "Clipping", string.Format("{0}, {1}, {2}, {3}", CroppingTop, CroppingLeft, CroppingBottom, CroppingRight), SettingsFile);
            ExternalAPI.WritePrivateProfileString("Settings", "Capture Rate", CaptureRate.ToString(), SettingsFile);
        }
Ejemplo n.º 7
0
        private void LoadSettings()
        {
            StringBuilder TempString = new StringBuilder(1024);

            ExternalAPI.GetPrivateProfileString("Capture", "Name", "", TempString, 1024, SettingsFile);
            WindowName = TempString.ToString();

            ExternalAPI.GetPrivateProfileString("Capture", "Title", "", TempString, 1024, SettingsFile);
            WindowTitle = TempString.ToString();

            ExternalAPI.GetPrivateProfileString("Capture", "Match Title", "False", TempString, 1024, SettingsFile);
            bool.TryParse(TempString.ToString(), out MatchWindowTitle);

            ExternalAPI.GetPrivateProfileString("Capture", "Topmost Only", "False", TempString, 1024, SettingsFile);
            bool.TryParse(TempString.ToString(), out TopmostOnly);

            ExternalAPI.GetPrivateProfileString("Capture", "Capture Method", "", TempString, 1024, SettingsFile);
            if (TempString.Length != 0)
            {
                Enum.TryParse <CaptureMethod>(TempString.ToString(), out Method);
            }


            ExternalAPI.GetPrivateProfileString("Settings", "Resize Output", "False", TempString, 1024, SettingsFile);
            bool.TryParse(TempString.ToString(), out ResizeOutput);

            ExternalAPI.GetPrivateProfileString("Settings", "Output Size", "1280, 720", TempString, 1024, SettingsFile);
            {
                int [] Values = SplitInput(TempString.ToString());
                if (Values.Length >= 2)
                {
                    ResizeOutputWidth  = Values[0];
                    ResizeOutputHeight = Values[1];
                }
            }

            ExternalAPI.GetPrivateProfileString("Settings", "Clipping", "0, 0, 0, 0", TempString, 1024, SettingsFile);
            {
                int[] Values = SplitInput(TempString.ToString());
                if (Values.Length >= 4)
                {
                    CroppingTop    = Values[0];
                    CroppingLeft   = Values[1];
                    CroppingBottom = Values[2];
                    CroppingRight  = Values[3];
                }
            }

            ExternalAPI.GetPrivateProfileString("Settings", "Capture Rate", "0", TempString, 1024, SettingsFile);
            int.TryParse(TempString.ToString(), out CaptureRate);
        }
Ejemplo n.º 8
0
        private void UpdateTimer_Tick(object sender, EventArgs e)
        {
            if (TopmostOnly && ExternalAPI.GetForegroundWindow() != WindowHandle)
            {
                return;
            }

            if (CapturePreview.Image != null)
            {
                CapturePreview.Image.Dispose();
            }

            CapturePreview.Image = ExternalAPI.CaptureWindow(WindowHandle, Method);
        }
Ejemplo n.º 9
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Create some classic menus so they arn't in the capture.
            IntPtr MenuHandle = ExternalAPI.CreateMenu();

            ExternalAPI.AppendMenu(MenuHandle, 0, 0x3000, "Capture...");
            ExternalAPI.AppendMenu(MenuHandle, 0, 0x3001, "Settings...");
            ExternalAPI.SetMenu(this.Handle, MenuHandle);

            UpdateCaptureCallback += UpdateCapture;

            Updater = new System.Threading.Thread(new System.Threading.ThreadStart(UpdateThread));
            Updater.Start();
        }
Ejemplo n.º 10
0
        public void UpdateThread()
        {
            while (true)
            {
                if (SettingOptionsWindow.Visible)
                {
                    System.Threading.Thread.Sleep(SettingOptionsWindow.CaptureRate);
                }
                else
                {
                    System.Threading.Thread.Sleep(CaptureRate);
                }

                if (CaptureOptionsWindow.Visible)
                {
                    continue;
                }

                // Only look up the Window if we don't have one, or if the one we have is no longer a window or is hidden
                if (MatchWindowHandle == IntPtr.Zero || !ExternalAPI.IsWindow(MatchWindowHandle) || !ExternalAPI.IsWindowVisible(MatchWindowHandle))
                {
                    bool A = ExternalAPI.IsWindow(MatchWindowHandle);
                    bool B = ExternalAPI.IsWindowVisible(MatchWindowHandle);

                    MatchWindowHandle = FindWindow(WindowName, WindowTitle, MatchWindowTitle);
                }

                if (TopmostOnly && ExternalAPI.GetForegroundWindow() != MatchWindowHandle)
                {
                    continue;
                }

                Bitmap Image = null;
                if (MatchWindowHandle != IntPtr.Zero)
                {
                    Image = ExternalAPI.CaptureWindow(MatchWindowHandle, Method);
                }

                this.Invoke(UpdateCaptureCallback, Image);
            }
        }
Ejemplo n.º 11
0
        void UpdateCapture(Bitmap Image)
        {
            if (Image == null)
            {
                if (PreviewScreen.Image != null)
                {
                    PreviewScreen.Image.Dispose();
                    PreviewScreen.Image = null;
                }

                return;
            }

            int height = Image.Height;
            int width  = Image.Width;

            if (SettingOptionsWindow.Visible)
            {
                height -= (SettingOptionsWindow.CroppingBottom + SettingOptionsWindow.CroppingTop);
                width  -= (SettingOptionsWindow.CroppingLeft + SettingOptionsWindow.CroppingRight);
            }
            else
            {
                height -= (CroppingBottom + CroppingTop);
                width  -= (CroppingLeft + CroppingRight);
            }

            if (width > 0 && height > 0)
            {
                if (PreviewScreen.Image != null)
                {
                    PreviewScreen.Image.Dispose();
                }

                try
                {
                    if (SettingOptionsWindow.Visible)
                    {
                        PreviewScreen.Image = Image.Clone(new Rectangle(SettingOptionsWindow.CroppingLeft, SettingOptionsWindow.CroppingTop, width, height), Image.PixelFormat);
                    }
                    else
                    {
                        PreviewScreen.Image = Image.Clone(new Rectangle(CroppingLeft, CroppingTop, width, height), Image.PixelFormat);
                    }
                }
                catch
                {
                    return;
                }

                int MenuThickness = ExternalAPI.GetSystemMetrics(15);

                if (SettingOptionsWindow.Visible)
                {
                    if (SettingOptionsWindow.ResizeOutput)
                    {
                        this.SetClientSizeCore(SettingOptionsWindow.ResizeOutputWidth, SettingOptionsWindow.ResizeOutputHeight + MenuThickness);
                    }
                    else
                    {
                        this.SetClientSizeCore(width, height + MenuThickness);
                    }
                }
                else
                {
                    if (ResizeOutput)
                    {
                        this.SetClientSizeCore(ResizeOutputWidth, ResizeOutputHeight + MenuThickness);
                    }
                    else
                    {
                        this.SetClientSizeCore(width, height + MenuThickness);
                    }
                }

                SettingOptionsWindow.WindowHeight = height;
                SettingOptionsWindow.WindowWidth  = width;
            }

            Image.Dispose();
        }