Sign in to follow this  
Followers 0
Yashied

_ScreenCapture_Capture()

3 posts in this topic

#1 ·  Posted (edited)

Why is the background disappears when I set HBITMAP to the control?

Thanks.

#Include <ScreenCapture.au3>
#Include <WinAPI.au3>

$hBitmap = _ScreenCapture_Capture('' , 0, 0, 400, 400, 0)

GUICreate('MyGUI', 400, 400)
$Pic = GUICtrlCreatePic('', 0, 0, 400, 400)
_SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBitmap) ; STM_SETIMAGE
GUISetState()

Do
Until GUIGetMsg() = -3

If I replaced SRCCOPY to MERGECOPY in _ScreenCapture_Capture() function, it will work but it is incorrectly.

Func __ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
    Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon

    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)
    If $iRight < $iLeft Then Return SetError(-1, 0, 0)
    If $iBottom < $iTop Then Return SetError(-2, 0, 0)

    $iW = $iRight - $iLeft
    $iH = $iBottom - $iTop
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, 0x00C000CA) ; MERGECOPY

    If $fCursor Then
        $aCursor = _WinAPI_GetCursorInfo()
        If $aCursor[1] Then
            $hIcon = _WinAPI_CopyIcon($aCursor[2])
            $aIcon = _WinAPI_GetIconInfo($hIcon)
            _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    EndIf

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

    _ScreenCapture_SaveImage($sFileName, $hBMP)
    _WinAPI_DeleteObject($hBMP)
EndFunc   ;==>__ScreenCapture_Capture

:)

Edited by Yashied

Share this post


Link to post
Share on other sites



Why is the background disappears when I set HBITMAP to the control?

Thanks.

#Include <ScreenCapture.au3>
#Include <WinAPI.au3>

$hBitmap = _ScreenCapture_Capture('' , 0, 0, 400, 400, 0)

GUICreate('MyGUI', 400, 400)
$Pic = GUICtrlCreatePic('', 0, 0, 400, 400)
_SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBitmap) ; STM_SETIMAGE
GUISetState()

Do
Until GUIGetMsg() = -3

If I replaced SRCCOPY to MERGECOPY in _ScreenCapture_Capture() function, it will work but it is incorrectly.

Func __ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
    Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon

    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)
    If $iRight < $iLeft Then Return SetError(-1, 0, 0)
    If $iBottom < $iTop Then Return SetError(-2, 0, 0)

    $iW = $iRight - $iLeft
    $iH = $iBottom - $iTop
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, 0x00C000CA) ; MERGECOPY

    If $fCursor Then
        $aCursor = _WinAPI_GetCursorInfo()
        If $aCursor[1] Then
            $hIcon = _WinAPI_CopyIcon($aCursor[2])
            $aIcon = _WinAPI_GetIconInfo($hIcon)
            _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    EndIf

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

    _ScreenCapture_SaveImage($sFileName, $hBMP)
    _WinAPI_DeleteObject($hBMP)
EndFunc ;==>__ScreenCapture_Capture

:)

This appears to work with or without your __ScreenCapture_Capture function.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

Local $hBitmap, $Pic, $hImage, $hBMP
$hBitmap = _ScreenCapture_Capture('', 0, 0, 360, 360, 0)

$hGUI = GUICreate('GUI with Pic control', 400, 400)
GUISetBkColor(0xBBBBBB, $hGUI)
$Pic = GUICtrlCreatePic('', 20, 20, 360, 360)

_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBMP) ; STM_SETIMAGE

_WinAPI_DeleteObject($hBMP)
_WinAPI_DeleteObject($hImage)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()

GUISetState()

Do
Until GUIGetMsg() = -3

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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
Sign in to follow this  
Followers 0