Sign in to follow this  
Followers 0
PhoenixXL

[SOLVED] GDI+ Path (Arc) Flickers upon reset

3 posts in this topic

#1 ·  Posted (edited)

Hello friends, here is the code

#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>


Global $GuiSizeX = 400, $GuiSizeY = 400, $iSlider[2], $iData[2]

$hGui = GUICreate("Paths", $GuiSizeX, $GuiSizeY)
GUICtrlCreateLabel("fStartAngle", 10, 300, -1, 15)
$iSlider[0] = GUICtrlCreateSlider(10, 320, 380, 20)
GUICtrlSetLimit(-1, 360, -360)

GUICtrlCreateLabel("fSweepAngle", 10, 350, -1, 15)
$iSlider[1] = GUICtrlCreateSlider(10, 370, 380, 20)
GUICtrlSetLimit(-1, 360, -360)

GUICtrlCreateButton("Set Arc", 320, 300, 60, 20)
GUICtrlCreateButton("Reset", 240, 300, 60, 20)

GUISetState()

_GDIPlus_Startup()

; Create Double Buffer, so the doesn't need to be repainted on PAINT-Event
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
;End Double Buffer add-in 1 of 3
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 1) ;Anti-Alias

Global $hPath = _GDIPlus_PathCreate()

; Create Double Buffer, so the doesn't need to be repainted on PAINT-Event
GUIRegisterMsg($WM_PAINT, "MY_PAINT"); Register PAINT-Event
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
;End Double Buffer add-in 2 of 3

Do
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_GDIPlus_PathDispose($hPath)

_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_BitmapDispose($hBMPBuff)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
ExitLoop
Case $iSlider[1] + 1
SetArc()
Case $iSlider[1] + 2
Erase()
EndSwitch
Until 0

;Func to redraw the BMP on PAINT MSG
Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
; Check, if the GUI with the Graphic should be repainted
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
EndFunc ;==>MY_PAINT

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)

$iData[0] = GUICtrlRead($iSlider[0])
$iData[1] = GUICtrlRead($iSlider[1])
ConsoleWrite(StringFormat("Start:%s\tSweep:%s\n", $iData[0], $iData[1]))

EndFunc ;==>WM_HSCROLL

Func SetArc()

_GDIPlus_PathAddArc($hPath, 0, 0, 90, 180, $iData[0], $iData[1])
_GDIPlus_GraphicsDrawPath($hGraphic, $hPath)
_GDIPlus_PathDispose($hPath)
$hPath = _GDIPlus_PathCreate()
_WinAPI_RedrawWindow($hGui, 0, 0, 2)

EndFunc ;==>SetArc

Func Erase()

_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_GDIPlus_GraphicsClear($hGraphicGUI, 0xFFFFFFFF)
_WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))

EndFunc ;==>Erase
Try pressing the reset button continuously, there is a white flicker observed sometimes. How can we eliminate that?

Thanks for your help and time :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Did you try @SW_LOCK / @SW_UNLOCK ?

Func Erase()
    GUISetState ( @SW_LOCK, $hGui )
    _GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
    _GDIPlus_GraphicsClear($hGraphicGUI, 0xFFFFFFFF)
    _WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))
    GUISetState ( @SW_UNLOCK, $hGui )
EndFunc ;==>Erase

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks wakillon, that worked :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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