VB.net Code (Using Win32API on VS2013)   Function Only  UTF-8 CRLF

    Public Function CaptureWindow(handle As IntPtr) As Image
        '' Based Code
        '' https://www.codeproject.com/Questions/743817/How-to-Capture-Aero-Window-all-states

        ''ToDo: Title Bar And Window Frame Not Correct! Why?

        ' get te hDC of the target window
        Dim hdcSrc As IntPtr = GetWindowDC(handle)
        ' get the size
        Dim windowRect As New RECT()
        GetWindowRect(handle, windowRect)

        'Dim R As Rectangle = GetAeroRect(handle) ' ------> NOTE 1#

        '' Add by me
        Dim windowRect2 As New RECT()
        If DwmGetWindowAttribute(handle, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, _
                                 windowRect2, System.Runtime.InteropServices.Marshal.SizeOf(windowRect2)) = True Then
            GetWindowRect(handle, windowRect2)
        End If
        '' End / Add by me

        '' Rev by me
        Dim width As Integer = windowRect2.right - windowRect2.left
        Dim height As Integer = windowRect2.bottom - windowRect2.top
        '' End / Rev by me

        ' create a device context we can copy to
        Dim hdcDest As IntPtr = CreateCompatibleDC(hdcSrc)
        ' create a bitmap we can copy it to,
        ' using GetDeviceCaps to get the width/height
        Dim hBitmap As IntPtr = CreateCompatibleBitmap(hdcSrc, width, height)
        ' select the bitmap object
        Dim hOld As IntPtr = SelectObject(hdcDest, hBitmap)

        '' Add by me
        ' Set Margin
        Dim marginX As Integer = windowRect2.left - windowRect.left
        Dim marginY As Integer = windowRect2.top - windowRect.top
        ' End / Add by me

        ' bitblt over

        '' Rev by me
        BitBlt(hdcDest, 0, 0, width, _
               height, hdcSrc, _
               marginX, marginY, CopyPixelOperation.SourceCopy)
        '' End / Rev by me

        ' restore selection
        SelectObject(hdcDest, hOld)
        ' clean up
        DeleteDC(hdcDest)
        ReleaseDC(handle, hdcSrc)
        ' get a .NET image object for it
        Dim img As Image = Image.FromHbitmap(hBitmap)
        ' free up the Bitmap object
        DeleteObject(hBitmap)
        Return img

    End Function