ImOracle

Problem with drawing a ScreencaptureWnd on GUI

8 posts in this topic

So im messing around with GDIPlus stuff and im creating an effect where, as long as the user holds down the Left mouse button, red circles are drawn, which increase with the time the left mouse button is held down. After the effect is over, i want to "erase" the circles from the gui.

I came up with the following idea: Just before i draw the circles, i make a screenshot of the gui using _screencapture_captureWnd and after the user releases the left mouse button, the Screenshot image is drawn on the gui, "erasing" the previously drawn circles.

Here is the main loop of my script

While 1
    Switch GUIGetMsg()
        Case -3
            _exit()
        Case $GUI_EVENT_MOUSEMOVE
            _drawRect()
        ;==> this is the important bit
        Case $GUI_EVENT_PRIMARYDOWN
            $saveImage = _ScreenCapture_CaptureWnd("", $mainGUI, Default, Default, Default, Default, False)
            $mouseX = MouseGetPos(0)
            $mouseY = MouseGetPos(1)
            $counter = 30
            $increase = 20
            While 1
                $counter += $increase
                _GDIPlus_GraphicsDrawEllipse($_Graphics, $mouseX-($counter/2), $mouseY-($counter/2), $counter, $counter, $redPen)
                Sleep(50)
                If GUIGetMsg() = $GUI_EVENT_PRIMARYUP Then
                    _GDIPlus_GraphicsDrawImageRect($_Graphics, $saveImage, 0, 0, @DesktopWidth, @DesktopHeight)
                    ExitLoop
                EndIf
            WEnd
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites



Bump

And here is the whole script (just something that went through my mind and a lot of free time/boredom)

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



Global Const $title = StringTrimRight(@ScriptName, 4)
Global $curBrush = 0
Global $redBrush = 0
Global $saveImage = 0

_GDIPlus_Startup()

$mainGUI = GUICreate($title, @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
$mainMenu = GUICtrlCreateContextMenu()
$restartMenuItem  = GUICtrlCreateMenuItem("Restart", $mainMenu)
GUISetState()
$_Graphics = _GDIPlus_GraphicsCreateFromHWND($mainGUI)
_GDIPlus_GraphicsClear($_Graphics, 0xFFFFFFFF)
Global $redPen = _GDIPlus_PenCreate(0xFFFF0000, 2)
While 1
    Switch GUIGetMsg()
        Case -3
            _exit()
        Case $GUI_EVENT_MOUSEMOVE
            _drawRect()
        Case $GUI_EVENT_PRIMARYDOWN
            $saveImage = _ScreenCapture_CaptureWnd("", $mainGUI, Default, Default, Default, Default, False)
            $mouseX = MouseGetPos(0)
            $mouseY = MouseGetPos(1)
            $counter = 30
            $increase = 20
            While 1
                $counter += $increase
                _GDIPlus_GraphicsDrawEllipse($_Graphics, $mouseX-($counter/2), $mouseY-($counter/2), $counter, $counter, $redPen)
                Sleep(50)
                If GUIGetMsg() = $GUI_EVENT_PRIMARYUP Then
                    _GDIPlus_GraphicsDrawImageRect($_Graphics, $saveImage, 0, 0, @DesktopWidth, @DesktopHeight)
                    ExitLoop
                EndIf
            WEnd
    EndSwitch
WEnd


Func _drawRect()
    Local $amountMin = 1
    Local $amountMax = 4

    Local $offsetXMin = -20
    Local $offsetXMax = 20
    Local $offsetYMin = -20
    Local $offsetYMax = 20

    Local $widthMin = 20
    Local $widthMax = 100
    Local $heightMin = 20
    Local $heightMax = 100

    Local $mouseX = MouseGetPos(0)
    Local $mouseY = MouseGetPos(1)

    $amount = Random($amountMin, $amountMax, 1)
    $curBrush = _GDIPlus_BrushCreateSolid(_randomColor())
    $offsetX = Random($offsetXMin, $offsetXMax, 1)
    $offsetY = Random($offsetYMin, $offsetYMax, 1)
    $width = Random($widthMin, $widthMax, 1)
    $height = Random($heightMin, $heightMax, 1)

    For $i = 0 To $amount
        _GDIPlus_GraphicsFillRect($_Graphics, $mouseX+$offsetX, $mouseY+$offsetY, $width, $height, $curBrush)
    Next
EndFunc

Func _randomColor()
    Local $red, $green, $blue, $color
    $red = Hex(Random(0, 255, 1), 2)
    $green = Hex(Random(0, 255, 1), 2)
    $blue = Hex(Random(0, 255, 1), 2)
    $color = "0xFF"&$red&$green&$blue
    Return $color
EndFunc



Func _exit()
    _GDIPlus_ImageDispose($saveImage)
    _GDIPlus_BrushDispose($curBrush)
    _GDIPlus_PenDispose($redPen)
    _GDIPlus_GraphicsDispose($_Graphics)
    _GDIPlus_Shutdown()
    Exit 1
EndFunc

 

art.au3

Share this post


Link to post
Share on other sites

can someone at least tell me if it works for them?

Share this post


Link to post
Share on other sites
While 1
    Switch GUIGetMsg()
        Case -3
            _exit()
        Case $GUI_EVENT_MOUSEMOVE
            _drawRect()
        Case $GUI_EVENT_PRIMARYDOWN
            ;$saveImage = _ScreenCapture_CaptureWnd("", $mainGUI, Default, Default, Default, Default, False)
            $mouseX = MouseGetPos(0)
            $mouseY = MouseGetPos(1)
            $counter = 30
            $increase = 20
            While 1
                $counter += $increase
                _GDIPlus_GraphicsDrawEllipse($_Graphics, $mouseX-($counter/2), $mouseY-($counter/2), $counter, $counter, $redPen)
                Sleep(50)
                If GUIGetMsg() = $GUI_EVENT_PRIMARYUP Then
                    ;_GDIPlus_GraphicsDrawImageRect($_Graphics, $saveImage, 0, 0, @DesktopWidth, @DesktopHeight)
                    _WinAPI_RedrawWindow($mainGUI)
                    ExitLoop
                EndIf
            WEnd
    EndSwitch
WEnd

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Interesting approach but not quite what i wanted to do

I may just try to create a buffer and draw the ellipses directly onto the graphics object...

Share this post


Link to post
Share on other sites

Try this:

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


_GDIPlus_Startup()

Global Const $title = StringTrimRight(@ScriptName, 4)
Global $curBrush = _GDIPlus_BrushCreateSolid(), $saveImageGDIp
Global $redBrush = 0
Global $saveImage = 0
Global $amountMin = 1
Global $amountMax = 4

Global $offsetXMin = -20
Global $offsetXMax = 20
Global $offsetYMin = -20
Global $offsetYMax = 20

Global $widthMin = 20
Global $widthMax = 100
Global $heightMin = 20
Global $heightMax = 100

$mainGUI = GUICreate($title, @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
$mainMenu = GUICtrlCreateContextMenu()
$restartMenuItem  = GUICtrlCreateMenuItem("Restart", $mainMenu)
GUISetState()
$_Graphics = _GDIPlus_GraphicsCreateFromHWND($mainGUI)
_GDIPlus_GraphicsSetSmoothingMode($_Graphics, 4)
_GDIPlus_GraphicsClear($_Graphics, 0xFFFFFFFF)
Global $redPen = _GDIPlus_PenCreate(0xFFFF0000, 2)
While 1
    Switch GUIGetMsg()
        Case -3
            _exit()
        Case $GUI_EVENT_MOUSEMOVE
            _drawRect()
        Case $GUI_EVENT_PRIMARYDOWN
            $saveImage = _ScreenCapture_CaptureWnd("", $mainGUI, Default, Default, Default, Default, False) ;this is a GDI bitmap
            $saveImageGDIp = _GDIPlus_BitmapCreateFromHBITMAP($saveImage) ;this is a GDI+ bitmap -> GDI <> GDI+!
            _WinAPI_DeleteObject($saveImage)
            $mouseX = MouseGetPos(0)
            $mouseY = MouseGetPos(1)
            $counter = 30
            $increase = 20
            While 1
                $counter += $increase
                _GDIPlus_GraphicsDrawEllipse($_Graphics, $mouseX-($counter/2), $mouseY-($counter/2), $counter, $counter, $redPen)
                Sleep(50)
                If GUIGetMsg() = $GUI_EVENT_PRIMARYUP Then
                    _GDIPlus_GraphicsDrawImageRect($_Graphics, $saveImageGDIp, 0, 0, @DesktopWidth, @DesktopHeight)
                    ExitLoop
                EndIf
            WEnd
            _GDIPlus_BitmapDispose($saveImageGDIp)
    EndSwitch
WEnd


Func _drawRect()
    Local $mouseX = MouseGetPos(0)
    Local $mouseY = MouseGetPos(1)

    $amount = Random($amountMin, $amountMax, 1)
    $offsetX = Random($offsetXMin, $offsetXMax, 1)
    $offsetY = Random($offsetYMin, $offsetYMax, 1)
    $width = Random($widthMin, $widthMax, 1)
    $height = Random($heightMin, $heightMax, 1)

    _GDIPlus_BrushSetSolidColor($curBrush, 0xFF000000 + 0x10000 * Random(0, 255, 1) + 0x100 * Random(0, 255, 1) + Random(0, 255, 1))

    For $i = 0 To $amount
        _GDIPlus_GraphicsFillRect($_Graphics, $mouseX+$offsetX, $mouseY+$offsetY, $width, $height, $curBrush)
    Next
EndFunc

Func _exit()
    _GDIPlus_ImageDispose($saveImageGDIp)
    _GDIPlus_BrushDispose($curBrush)
    _GDIPlus_PenDispose($redPen)
    _GDIPlus_GraphicsDispose($_Graphics)
    _GDIPlus_Shutdown()
    Exit 1
EndFunc

 

Don't mix up GDI with GDI+ handles!


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Try this:

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


_GDIPlus_Startup()

Global Const $title = StringTrimRight(@ScriptName, 4)
Global $curBrush = _GDIPlus_BrushCreateSolid(), $saveImageGDIp
Global $redBrush = 0
Global $saveImage = 0
Global $amountMin = 1
Global $amountMax = 4

Global $offsetXMin = -20
Global $offsetXMax = 20
Global $offsetYMin = -20
Global $offsetYMax = 20

Global $widthMin = 20
Global $widthMax = 100
Global $heightMin = 20
Global $heightMax = 100

$mainGUI = GUICreate($title, @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
$mainMenu = GUICtrlCreateContextMenu()
$restartMenuItem  = GUICtrlCreateMenuItem("Restart", $mainMenu)
GUISetState()
$_Graphics = _GDIPlus_GraphicsCreateFromHWND($mainGUI)
_GDIPlus_GraphicsSetSmoothingMode($_Graphics, 4)
_GDIPlus_GraphicsClear($_Graphics, 0xFFFFFFFF)
Global $redPen = _GDIPlus_PenCreate(0xFFFF0000, 2)
While 1
    Switch GUIGetMsg()
        Case -3
            _exit()
        Case $GUI_EVENT_MOUSEMOVE
            _drawRect()
        Case $GUI_EVENT_PRIMARYDOWN
            $saveImage = _ScreenCapture_CaptureWnd("", $mainGUI, Default, Default, Default, Default, False) ;this is a GDI bitmap
            $saveImageGDIp = _GDIPlus_BitmapCreateFromHBITMAP($saveImage) ;this is a GDI+ bitmap -> GDI <> GDI+!
            _WinAPI_DeleteObject($saveImage)
            $mouseX = MouseGetPos(0)
            $mouseY = MouseGetPos(1)
            $counter = 30
            $increase = 20
            While 1
                $counter += $increase
                _GDIPlus_GraphicsDrawEllipse($_Graphics, $mouseX-($counter/2), $mouseY-($counter/2), $counter, $counter, $redPen)
                Sleep(50)
                If GUIGetMsg() = $GUI_EVENT_PRIMARYUP Then
                    _GDIPlus_GraphicsDrawImageRect($_Graphics, $saveImageGDIp, 0, 0, @DesktopWidth, @DesktopHeight)
                    ExitLoop
                EndIf
            WEnd
            _GDIPlus_BitmapDispose($saveImageGDIp)
    EndSwitch
WEnd


Func _drawRect()
    Local $mouseX = MouseGetPos(0)
    Local $mouseY = MouseGetPos(1)

    $amount = Random($amountMin, $amountMax, 1)
    $offsetX = Random($offsetXMin, $offsetXMax, 1)
    $offsetY = Random($offsetYMin, $offsetYMax, 1)
    $width = Random($widthMin, $widthMax, 1)
    $height = Random($heightMin, $heightMax, 1)

    _GDIPlus_BrushSetSolidColor($curBrush, 0xFF000000 + 0x10000 * Random(0, 255, 1) + 0x100 * Random(0, 255, 1) + Random(0, 255, 1))

    For $i = 0 To $amount
        _GDIPlus_GraphicsFillRect($_Graphics, $mouseX+$offsetX, $mouseY+$offsetY, $width, $height, $curBrush)
    Next
EndFunc

Func _exit()
    _GDIPlus_ImageDispose($saveImageGDIp)
    _GDIPlus_BrushDispose($curBrush)
    _GDIPlus_PenDispose($redPen)
    _GDIPlus_GraphicsDispose($_Graphics)
    _GDIPlus_Shutdown()
    Exit 1
EndFunc

 

Don't mix up GDI with GDI+ handles!

wow that was a lot easier than i thought

Thanks!

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