Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

capture second screen desktop (windows 10) c#

hello everyone
when i made two desktops on windows 10 and try to capture screen . i succeed to capture the first desktop but the second desktop captured screen became blank?
how to capture second desktop screen?
(Mar 29, 2021 04:09 PM)hacker dz Wrote:  hello everyone
when i made two desktops on windows 10 and try to capture screen . i succeed to capture the first desktop but the second desktop captured screen became blank?
how to capture second desktop screen?

what screen capture app are you using , and i think its in the wrong section
(Mar 29, 2021 04:09 PM)hacker dz Wrote:  hello everyone
when i made two desktops on windows 10 and try to capture screen . i succeed to capture the first desktop but the second desktop captured screen became blank?
how to capture second desktop screen?

You may have to use some sort of SetDesktop API maybe?
[Image: Syr3DlV.png]
Not sure i understand your request maybe this what you search.

Code
    public static class ScreenHelper
    {

        [DllImport("gdi32.dll", CharSet = CharSet.Unicode)]
        internal static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);

        [DllImport("gdi32.dll", EntryPoint = "BitBlt", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
       
        [DllImport("gdi32.dll")]
        internal static extern bool DeleteDC([In] IntPtr hdc);

        private const int SRCCOPY = 0x00CC0020;

        public static Bitmap CaptureScreen(int screenNumber)
        {
            Rectangle bounds = GetBounds(screenNumber);
            Bitmap screen = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppPArgb);

            using (Graphics g = Graphics.FromImage(screen))
            {
                IntPtr destDeviceContext = g.GetHdc();
                IntPtr srcDeviceContext = CreateDC("DISPLAY", null, null, IntPtr.Zero);

                BitBlt(destDeviceContext, 0, 0, bounds.Width, bounds.Height, srcDeviceContext, bounds.X,
                    bounds.Y, SRCCOPY);

                DeleteDC(srcDeviceContext);
                g.ReleaseHdc(destDeviceContext);
            }

            return screen;
        }

        public static Rectangle GetBounds(int screenNumber)
        {
            return Screen.AllScreens[screenNumber].Bounds;
        }
    }


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by salemxx66Sep 30, 2021 08:39 PM 0 130 Sep 30, 2021 08:39 PM
Last Post: salemxx66
[Shell] by Emre_Jan 12, 2021 11:16 PM 0 141 Jan 12, 2021 11:16 PM
Last Post: Emre_
[C#] by maypeApr 8, 2018 04:53 PM 6 291 Apr 8, 2018 04:53 PM
Last Post: Ninja