Jump to content

_ScreenCapture_Capture ignoring semi transparent windows.


milos83
 Share

Recommended Posts

If I set the transparency with WinSetTrans, screenshot can't be made.

This is Windows 7 related.

Win 10 works fine

Run the attached file

#include <ScreenCapture.au3>

;GUI1
$gui1 = GUICreate("gui1", 200, 200, 200, 200)
GUICtrlCreateLabel("GUI 1 LABEL", 50, 50 )
GUISetState()

;GUI 2 with transparency is completely ignored by _ScreenCapture_Capture
$gui2 = GUICreate("gui1", 200, 200, 200, 200, -1, -1, $gui1)
GUICtrlCreateLabel("GUI 2 LABEL", 100, 100 )
GUISetState()

WinSetTrans($gui2, "", 150)


Sleep(2000)

_ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image1.jpg", 200, 200, 405, 410)
ShellExecute(@MyDocumentsDir & "\GDIPlus_Image1.jpg")

As you can see, the semi transparent window will not be visible in the screenshot.

I noticed that a couple of screen recording tools are acting the same. (But there are those that do work)

I tried different ways on getting the screenshot and none worked.

Printscreen does work.

Is there a way to solve this without using Printscreen?

ScreenCaptureProblem.au3

Edited by milos83
Link to comment
Share on other sites

On 16.02.2018 at 8:20 PM, milos83 said:

Any way to fix it without turning Aero theme on?

Try to change _ScreenCapture_Capture: add $CAPTUREBLT from WindowsConstants.au3 to _WinAPI_BitBlt

_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, BitOR($__SCREENCAPTURECONSTANT_SRCCOPY, $CAPTUREBLT))

 

Link to comment
Share on other sites

On 2/18/2018 at 10:10 AM, InnI said:

Try to change _ScreenCapture_Capture: add $CAPTUREBLT from WindowsConstants.au3 to _WinAPI_BitBlt

_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, BitOR($__SCREENCAPTURECONSTANT_SRCCOPY, $CAPTUREBLT))

 

That does the trick!
Since I don't know if there are any side effects I am using this alternative only if WIN7+AeroOFF.
 

Func _ScreenCapture_Capture2($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $bCursor = True)
    Local $bRet = False
    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN) - 1
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN) - 1
    If $iRight < $iLeft Then Return SetError(-1, 0, $bRet)
    If $iBottom < $iTop Then Return SetError(-2, 0, $bRet)

    Local $iW = ($iRight - $iLeft) + 1
    Local $iH = ($iBottom - $iTop) + 1
    Local $hWnd = _WinAPI_GetDesktopWindow()
    Local $hDDC = _WinAPI_GetDC($hWnd)
    Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
;~  _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $__SCREENCAPTURECONSTANT_SRCCOPY)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, BitOR($__SCREENCAPTURECONSTANT_SRCCOPY, $CAPTUREBLT))

    If $bCursor Then
        Local $aCursor = _WinAPI_GetCursorInfo()
        If Not @error And $aCursor[1] Then
            $bCursor = True ; Cursor info was found.
            Local $hIcon = _WinAPI_CopyIcon($aCursor[2])
            Local $aIcon = _WinAPI_GetIconInfo($hIcon)
            If Not @error Then
                _WinAPI_DeleteObject($aIcon[4]) ; delete bitmap mask return by _WinAPI_GetIconInfo()
                If $aIcon[5] <> 0 Then _WinAPI_DeleteObject($aIcon[5]); delete bitmap hbmColor return by _WinAPI_GetIconInfo()
                _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)
            EndIf
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    EndIf

    _WinAPI_ReleaseDC($hWnd, $hDDC)
    _WinAPI_DeleteDC($hCDC)
    If $sFileName = "" Then Return $hBMP

    $bRet = _ScreenCapture_SaveImage($sFileName, $hBMP, True)
    Return SetError(@error, @extended, $bRet)
EndFunc   ;==>_ScreenCapture_Capture

Thank you @InnI

 

Edited by milos83
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...