Jump to content

how to auto send screen picture on application to gui


yalil
 Share

Recommended Posts

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                While 1
                GUICtrlSetData($Input1,@ScriptDir & "\Screenshot_1.png")
                $hImage = _LoadImage($Input1, $Pic1, $hImage, $iPicW,$iPicH)
                Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000)

how can i add a function to capture a picture form application and send it to 'GUICtrlSetData($Input1,@ScriptDir & "\Screenshot_1.png")'

Link to comment
Share on other sites

Take an example

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

Local $hGUI = GUICreate("MyGUI", 480, 350, -1, -1, -1, $WS_EX_TOPMOST)
Local $Pic1 = GUICtrlCreatePic("", 0, 0, 480, 320)
Local $Label1 = GUICtrlCreateLabel("Label1", 10, 325, 400, 17)
Local $Button1 = GUICtrlCreateButton("Capture", 420, 325, 51, 21)
GUISetState(@SW_SHOW)

Local $hWnd, $WPos, $Pic_cnt = 1

Local $iMsgBoxAnswer, $Msg
$Msg = "First Select (Activate) the window" & @CRLF _
         & " you wand the capture " & @CRLF _
         & "and then click ok"

$iMsgBoxAnswer = MsgBox($MB_OKCANCEL + $MB_TOPMOST + $MB_ICONINFORMATION, "Get Menu Information", $Msg)
Select
    Case $iMsgBoxAnswer = 1     ;OK
        ; ok
    Case $iMsgBoxAnswer = 2     ;Cancel
        Exit
EndSelect

; Retrieve the class of the active window.
$hWnd = WinGetHandle("[ACTIVE]")
WinWaitActive($hWnd, "", 5)

; If the directory exists Remove the directory
If FileExists(@ScriptDir & "\Shots") Then
    DirRemove(@ScriptDir & "\Shots", $DIR_REMOVE)
EndIf
; and then make new directory
DirCreate (@ScriptDir & "\Shots")

While 1
    $WPos = WinGetPos($hWnd)
    ; [0]=X  [1]=Y  [2]=Width  [3]=Height
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop
        Case $Button1
            TakeShot()
    EndSwitch

    Sleep(10)
WEnd


Func TakeShot()
    ; Capture region
    _ScreenCapture_Capture(@ScriptDir & "\Shots\shot_" & $Pic_cnt & ".jpg", $WPos[0], $WPos[1], $WPos[2], $WPos[3])
    Sleep(50)
    GUICtrlSetImage($Pic1, @ScriptDir & "\Shots\shot_" & $Pic_cnt & ".jpg")
    GUICtrlSetData($Label1, @ScriptDir & "\Shots\shot_" & $Pic_cnt & ".jpg")
    $Pic_cnt += 1

EndFunc   ;==>TakeShot

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Here's a lightly modified code from my post here:

 

This uses _ScreenCapture_Capture to constantly take a screenshot of a part of the screen, and then update/draw it onto a GUI. I think that it should have everything that you need, if you want to pick it part.

#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPIDiag.au3>
#include <WinAPISysWin.au3>

_GDIPlus_Startup()
Local $hGUI = GUICreate("GDI+ test", @DesktopWidth, @DesktopHeight, 0, 0, _
        $WS_POPUP, _
        $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetStyle(BitOR($WS_POPUP, $WS_VISIBLE), BitOR($WS_DISABLED, $WS_EX_TRANSPARENT, $WS_EX_LAYERED))
GUISetBkColor(0x000000)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0x000000)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUISetState()
HotKeySet("{ESC}", "__Exit")
OnAutoItExitRegister('__Exit')

WinSetTrans($hGUI, '', 128)

ConsoleWrite('Drawn GUI' & @CRLF)

While 1
    __UpdateGUI()
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func __UpdateGUI()
    Local $hUpdateTimer = TimerInit()
    Local $sMsg = ''
    Local $hTimer = TimerInit()
    Local $aStats[] = [True, 200, 200, 800, 4] ;= __PixelSearch_GetImgStats() ; True, Width, Height, Stride, BitsPerPixel (bpp)
    Local $iSize = ($aStats[1] * $aStats[2])
    $sMsg = 'SS - ' & Round(TimerDiff($hTimer), 2) & 'ms'

    Local $aScan[$iSize] ;= __PixelSearch_GetScan0()
    $hTimer = TimerInit()
;~  Local $iX = Random(300,400,1), $iY = Random(300,400,1)
    Local $iX = 300, $iY = 300
    Local $hScreenShot = _ScreenCapture_Capture('', $iX, $iY, $iX + 200,$iY + 200)
    $hScreenShot = _GDIPlus_BitmapCreateFromHBITMAP($hScreenShot)
    $sMsg = $sMsg & ', _ScreenCapture_Capture - ' & Round(TimerDiff($hTimer), 2) & 'ms'

    $hTimer = TimerInit()
;~     _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, (@DesktopWidth / 2), @DesktopHeight / 2)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hScreenShot, (@DesktopWidth / 2), @DesktopHeight / 2)
    $sMsg = $sMsg & ', Draw - ' & Round(TimerDiff($hTimer), 2) & 'ms'

    $sMsg = $sMsg & ', Total - ' & Round(TimerDiff($hUpdateTimer), 2) & 'ms'

    ConsoleWrite($sMsg & @CRLF)
EndFunc   ;==>__UpdateGUI

Func __Exit()
    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>__Exit

 

Keep in mind though that if you're trying to play a 'video' or something similar with this method it's not going to work out well. It runs at an acceptable rate for 200x200px, but as you start to go higher it'll start to run pretty slowly. Also, you need to have line of sight to what it's copying/displaying which means you can't play a video, minimize it, and have it display in your GUI.

We ought not to misbehave, but we should look as though we could.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...