How can take an screenshot for an specific section in a windows universal app (doesn't matter the computer resolution)

0

I'm working in a company where the owner wish take a screenshot of a windows mail app; specifically the section where the e-mail are show; and if the window or the section have an scroll, then must avoid it and take the screenshot of that whole section.

I'm building it on a .net console app, and I have download a lot of examples where shows just how to take a screeshot of an specific or any window.

The closest code (I think) that I found was this:

IntPtr current = IntPtr.Zero;
        IntPtr handle = IntPtr.Zero;

        List<IntPtr> thumbs = new List<IntPtr>();
        if (handle == IntPtr.Zero)
            handle = ((System.Windows.Interop.HwndSource)System.Windows.Interop.HwndSource.FromVisual(this)).Handle;

        current = DWM.GetWindow(handle, DWM.GetWindowCmd.First);

        do
        {
            int GWL_STYLE = -16;
            int TASKSTYLE = 0x10000000 | 0x00800000;
            if (TASKSTYLE == (TASKSTYLE & DWM.GetWindowLong(current, GWL_STYLE)))
            {
                thumbs.Add(current);
            }

            current = DWM.GetWindow(current, DWM.GetWindowCmd.Next);

            if (current == handle)
                current = DWM.GetWindow(current, DWM.GetWindowCmd.Next);
        }
        while (current != IntPtr.Zero);

        this.DataContext = thumbs;

What customer expects it's to take an screenshot of a windows mail app but as I said before, the section that shows the e-mail in fact. So, it must looks something like:

Result

c#
.net
decompiler

1 Answer

0

I am not sure how to do it from a Console Application, as that is very limited, but you can create a screen capture program from Windows Forms significantly easier. The course I took from Huw Collingbourne who will teach you how to do it. It is not a small program to type out in this box though.

The program he teaches had a mainform, then would pop up a smaller transparent form that you would maneuver over the area you want to capture. To capture you would press the button which would capture the transparent form with this code:

formRect = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
this.Hide();
mainForm.GrabRect(formRect);

Going back to the main form the program would put the picture on the picturebox for you to view.

public void GrabRect(Rectangle rect)
    {
        int rectWidth = rect.Width - rect.Left;
        int rectHeight = rect.Height - rect.Top;
        Bitmap bm = new Bitmap(rectWidth, rectHeight);
        Graphics g = Graphics.FromImage(bm);
        g.CopyFromScreen(rect.Left, rect.Top, 0, 0, new Size(rectWidth, rectHeight));
        this.pb_screengrab.Image = bm;
        Clipboard.SetImage(bm);
        g.Dispose();
    }

Here are the links to his course https://bitwisecourses.com/p/program-a-screen-capture-tool-in-c-sharp and his course sold through udemy https://www.udemy.com/course/program-a-screen-capture-tool-in-c/learn/lecture/15760316#content

bitwisecourses.com is his direct website I believe. Otherwise Udemy will offer nice discounts like $10-$13 for their various classes. Once you bought a bunch and don’t do anything for a few months they will try to charge you full price, but you only need to email them and they will start discounting you again.

I put everything I did here: https://github.com/johnbnstx/HuwBurn_ScreenGrab

I hope this helps.

answered on Stack Overflow Oct 25, 2019 by John B

User contributions licensed under CC BY-SA 3.0