Sign in to follow this  
Followers 0
Malkey

Random GDI+ Objects

2 posts in this topic

#1 ·  Posted (edited)

Furthering my fascination with GDI+ functions and inspired by the recent Gdi+Star post, I continue the journey to the past.

The first script, I think, first appeared 20 to 30 years ago. The controls are:-

Esc key - Exit

Alt key - toggles pause of the display

Ctrl key - Repeated presses changes the Gdi+ objects - rectangles, elliipses, lines , then all together.

F10 key - Saves the display to @ScriptDir & "\GDIPlus_Image.jpg

For referance, the above appear in the window title bar with the picture size, which will result if F10 is pressed. The update of the picture size on the title bar is a bit slow changing, after resizing the window.

;
 #include <GDIPlus.au3>
 #include <ScreenCapture.au3>
 #include <GUIConstants.au3>
 #include <WindowsConstants.au3>
 #include <Misc.au3>
 
 Global $dll = DllOpen ("user32.dll")
 Global $winpos, $GuiSizeW = 500, $GuiSizeH = 522, $pause = "no"
 Local $sSpeed, $hWnd, $hGraphic, $hImage1, $hBitmap, $hBitmap1, $blackBrush, $randBrush, $nMsg, $flg = 1
 Local $titl = "GDI+ Toggle Alt->Pause; Ctrl->Change; F10->Copy2File; PictSize->" & $GuiSizeW & "x" & $GuiSizeH - 22
 Opt("GUIOnEventMode", 0)
 Opt('MustDeclareVars', 1)
 Opt("WinTextMatchMode", 2)
 
 $hWnd = GUICreate($titl, $GuiSizeW, $GuiSizeH, -1, -1, BitOR($WS_SIZEBOX,$WS_DLGFRAME,$WS_CLIPSIBLINGS))
 
 GUISetBkColor(0xff000000)
 GUISetState()
 
 _GDIPlus_Startup ()
 
 Do
 $nMsg = GUIGetMsg()
 Select
 Case $nMsg = $GUI_EVENT_CLOSE
 ExitLoop
 Case _IsPressed("11"); CTRL key
 $winpos = WinGetPos("GDI+")
 WinMove ( "GDI+", "",$winpos[0], $winpos[1],$winpos[2]-10, $winpos[3]-10 )
 Sleep(50)
 WinMove ( "GDI+", "",$winpos[0], $winpos[1],$winpos[2]+10, $winpos[3]+10)
 $flg += 1
 $pause = "no"
 Case _IsPressed("12"); ALT key
 Sleep(250)
 If $pause = "no" Then
 $pause = "yes"
 Else
 $pause = "no"
 EndIf
 
 Case _IsPressed("79"); F10 key
 _ScreenCapture_CaptureWnd (@ScriptDir & "\GDIPlus_Image.jpg", $hWnd, 0, 22, $GuiSizeW, $GuiSizeH)
 
 Case $nMsg = $GUI_EVENT_RESIZED
 $pause = "yes"
 $winpos = WinGetPos("GDI+")
 $GuiSizeW = $winpos[2]
 $GuiSizeH = $winpos[3]
 $titl = "GDI+ Toggle Alt->Pause; Ctrl->Change; F10->Copy2File; PictSize->" & $GuiSizeW _
 & "x" & $GuiSizeH - 22
 WinSetTitle("GDI+", "", $titl )
 $pause = "no"
 EndSelect
 
 $sSpeed = Random(30, 150, 1)
 If $pause = "no" Then
;Sleep(10)
 If $flg = 1 Or $flg = 4 Then GDIPlus_Rectangles($hWnd, $sSpeed)
;Sleep(10)
 If $flg = 2 Or $flg = 4 Then GDIPlus_Ellipses ($hWnd, $sSpeed)
;Sleep(10)
 If $flg = 3 Or $flg = 4 Then GDIPlus_Lines ($hWnd, $sSpeed)
 If $flg >= 5 Then $flg = 1
 Sleep($sSpeed)
 EndIf
 
 Until _IsPressed("1B"); ESC key
 DllClose($dll)
 _GDIPlus_Shutdown ()
 
 Func GDIPlus_Rectangles($hWnd, $sSpeed = 0 )
 Local $iX, $iY, $iWidth, $iHeight
 $iX = Random(-10,$GuiSizeW, 1)
 $iY = Random(-10,$GuiSizeH, 1)
 $iWidth = Random(1,$GuiSizeW/2, 1)
 $iHeight = Random(1,$GuiSizeH/2, 1)
 
 $randBrush = _GDIPlus_BrushCreateSolid ( Random(0xff000000, 0xffffff00, 2))
 $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
 _GDIPlus_GraphicsFillRect ($hGraphic, $iX, $iY, $iWidth, $iHeight, $randBrush)
 _GDIPlus_GraphicsDispose ($hGraphic)
 _GDIPlus_BrushDispose ($randBrush)
 EndFunc
 
 Func GDIPlus_Ellipses($hWnd, $sSpeed = 0 )
 Local $hGraphic,$blackBrush,$iX, $iY, $iWidth, $iHeight
 $iX = Random(-10,$GuiSizeW*3/4, 1)
 $iY = Random(-10,$GuiSizeH*3/4, 1)
 $iWidth = Random(1,$GuiSizeW/2, 1)
 $iHeight = Random(1,$GuiSizeH/2, 1)
 $randBrush = _GDIPlus_BrushCreateSolid ( Random(0xff000000, 0xffffff00, 2))
 $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
;Sleep($sSpeed)
 _GDIPlus_GraphicsFillEllipse ($hGraphic, $iX, $iY, $iWidth, $iHeight, $randBrush)
 _GDIPlus_GraphicsDispose ($hGraphic)
 _GDIPlus_BrushDispose ($randBrush)
 EndFunc
 
 Func GDIPlus_Lines($hWnd, $sSpeed = 0 )
 Local $hGraphic,$iX, $iY, $iX2, $iY2, $hPen
 $iX = Random(0, $GuiSizeW + 20, 1)
 $iY = Random(0, $GuiSizeH, 1)
 $iX2 = Random(0, $GuiSizeW +20,1)
 $iY2 = Random(0, $GuiSizeH,1)
 $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
 $hPen = _GDIPlus_PenCreate (Random(0xff000000, 0xffffff00, 1), Random(0, 6, 1), 2 )
 _GDIPlus_GraphicsDrawLine ($hGraphic, $iX, $iY, $iX2, $iY2, $hPen)
 _GDIPlus_PenDispose ($hPen)
 _GDIPlus_GraphicsDispose ($hGraphic)
 EndFunc
;<gdiplus.au3><screencapture.au3><guiconstants.au3><windowsconstants.au3><misc.au3>

I really just wanted to know if this could be done.

Edit: Included $includes - This is not the first time the includes did not copy across. In the past I have noticed this before the initial post.

Edit:Changed to CODE box and updated

Edited by Malkey

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Are the includes on your first script supposed to be missing?? :D

Anyhow, I got it to run by adding:

#include <GuiConstantsEx.au3>
#include <ScreenCapture.au3>
no biggie...

Also your second script doesn't cover the whole screen, possibly because i have 2 monitors running dualview, my setup is:

Screen nr1= 0x0 to 1600x1200

Screen nr2= -1024x432 to 0x1200

Your script only seems to cover somewhere around 0x0 to 1600x1000

Other than those two issues it's looking really good :);)

Edited by TzarAlkex

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