Jump to content
milos83

_ScreenCapture_Capture ignoring semi transparent windows.

Recommended Posts

milos83

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

Share this post


Link to post
Share on other sites
InnI
1 hour ago, milos83 said:

This is Windows 7 related.

It seems like you use basic windows theme without aero. If so then choose some aero theme and try again.

Share this post


Link to post
Share on other sites
milos83
5 hours ago, InnI said:

It seems like you use basic windows theme without aero. If so then choose some aero theme and try again.

You are right!

Any way to fix it without turning Aero theme on?

Share this post


Link to post
Share on other sites
InnI
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))

 

Share this post


Link to post
Share on other sites
milos83
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

Share this post


Link to post
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

  • Similar Content

    • sharkeye
      By sharkeye
      #include <ScreenCapture.au3> Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") _ScreenCapture_SaveImage("C:\Software\autoitscripts\scripts\images\prp\ocr\"&"ocr_01.PNG",$hBmp) Sleep(1000) _ScreenCapture_Capture("C:\Software\autoitscripts\scripts\images\prp\ocr\"&"ocr_02.PNG") Sleep(1000) ShellExecute("C:\Software\autoitscripts\scripts\images\prp\ocr\"&"ocr_01.PNG") Sleep(1000) ShellExecute("C:\Software\autoitscripts\scripts\images\prp\ocr\"&"ocr_02.PNG") Hi All,
      This is my first post and I have checked the forum.  If this question has been asked and answered I apologise.
      The code above is intended to save the whole screen to a directory; it doesn't work.
      I have downloaded and copied and renamed the files referenced in https://www.autoitscript.com/forum/topic/192254-33143-fixes/ to my includes directory.
      Clearly there is some step that I am missing; do I need to download and register a dll?
       
      I know that I am using two different methods above but neither works for me.
    • odaylton
      By odaylton
      I would like to get a region of the screen but avoiding having to save to a file first.
      I believe it is a lack of knowledge on my part but the GUICtrlSetImage function does not allow you to define an image without being a file.
      How to do this:
      ;.... $Pic3 = GUICtrlCreatePic("", 8, 64, 84, 84, -1, _ $WS_EX_STATICEDGE) ;para ter borda em baixo relevo ;.... _ScreenCapture_Capture(@ScriptDir & "\areatemp.jpg", 10, 10, 200, 200) GUICtrlSetImage($Pic3, @ScriptDir & "\areatemp.jpg") ;....  
    • ashly
      By ashly
      i'm trying to use _ScreenCapture_Capture($sFileName) to cature full screen and save as a jpg file, but it always only capture the left-top about 3/4 area.
      but the print screen keyboard woks fine.
      and if i changed the display resolution from 150% to 100%, the jpg file is OK as well.
      so the issue only occurred when resolution is 150%.
      is there anybody know why or how to change resolution percentage by scripts?
      Thanks.
×