Jump to content
Sign in to follow this  

screen capture to clip board ,

Recommended Posts


i cant figure out how to get a $Hbit = _ScreenCapture_Capture() into the clip board, have read and tried some udf's made for this but im even more confused now.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <Clipboard.au3>
$oldWhnd = 0
$hGUI = GUICreate("Clipboard", 600, 400)
While 1
    $W_or_ctrl_hnd = getctrl()
    If $W_or_ctrl_hnd <> $oldWhnd Then
        _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
        If WinExists($W_or_ctrl_hnd) Then
            $winpos = hilightwin($W_or_ctrl_hnd)
            $oldWhnd = $W_or_ctrl_hnd
    If _IsPressed("01") Then
        $Hbit = _ScreenCapture_Capture($winpos[0], $winpos[1], $winpos[2], $winpos[3])
        _ClipBoard_SetDataEx($Hbit, $CF_BITMAP)
;~      _ClipBoard_SetData($Hbit, $CF_BITMAP)
;~ _ClipBoard_SetHBITMAP($Hbit)
Func getctrl()
    $pos = _WinAPI_GetMousePos()
    $Hwinx = _WinAPI_WindowFromPoint($pos)
    Return $Hwinx
Func hilightwin($Hwin)
    Local $hDC, $hPen, $obj_orig
    Local $winposx[4]
    $winpos = WinGetPos($Hwin)
    $hDC = _WinAPI_GetWindowDC(0); DC of entire screen (desktop)
    $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x00ff00)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
    $winposx[0] = $winpos[0]
    $winposx[1] = $winpos[1]
    $winposx[2] = $winpos[0] + $winpos[2]
    $winposx[3] = $winpos[1] + $winpos[3]
    _WinAPI_DrawLine($hDC, $winposx[0] + 3, $winposx[1] + 3, $winposx[2] - 3, $winposx[1] + 3)
    _WinAPI_DrawLine($hDC, $winposx[2] - 3, $winposx[1] + 3, $winposx[2] - 3, $winposx[3] - 3)
    _WinAPI_DrawLine($hDC, $winposx[2] - 3, $winposx[3] - 3, $winposx[0] + 3, $winposx[3] - 3)
    _WinAPI_DrawLine($hDC, $winposx[0] + 3, $winposx[3] - 3, $winposx[0] + 3, $winposx[1] + 3)
    _WinAPI_SelectObject($hDC, $obj_orig)
    _WinAPI_ReleaseDC(0, $hDC)
    Return $winposx

;;   test func from AutoIt forum 

Func _ClipBoard_SetHBITMAP($hBitmap, $Empty = 1)
    If $Empty Then _ClipBoard_Empty()
    _ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
    If Not _ClipBoard_IsFormatAvailable($CF_BITMAP) Then
        Return SetError(1, 0, 0)

_AutoItWinGetHandle() i duno what this command is so the func at the end of script dont work , and im still stuck. id like to be able to paste to Paint after capture just as a test that its working. i know its capturing the right area as i tried _ScreenCapture_Capture(@ScriptDir & "\test.jpg",$winpos[0], $winpos[1], $winpos[2], $winpos[3]) and thats ok

Edited by JackDinn

Thx all,Jack Dinn.


JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

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