Jump to content

Recommended Posts

Posted

hey guys, i've got another GDI issue :huh2:

no matter what i do to this code i can't get the flicker to stop when i'm redrawing.

(use the Arrow Keys (UP & DOWN)

also, when i set $scale to 2 it runs fairly smoothly.. but when i set it to anything smaller than 1.7 (for a bigger screen) it becomes unresponsive and the only thing that happens is it closes on ESC. Why? what am i doing wrong?

spent a couple hours looking it up, maybe i'm blind or something... haven't found my answer yet.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Global $State = False
Global $Buffer_Speed = 45, $key_count = 0
Global $Black = '000000', $Blue = '0000AA', $Red = 'AA0000', $White = 'FFFFFF'
Global $hBB_BMP, $hBB_Graphic, $hGraphic, $hRed, $hBlue, $hWhite, $hBlack, $hFamily,$hFont, $hFormat
Global $scale = 2
Global $hWnd, $height=@DesktopHeight/$scale, $width=@DesktopWidth/$scale, $style=$WS_POPUP, $exstyle=BitOR ($WS_EX_APPWINDOW,$WS_EX_TOPMOST)



init ()

;===================
;MAIN LOOP
;===================
While True
    Switch $State
        Case 'main'
            main ()
        Case False
            quit ()
        Case Else
            ;do nothing
    EndSwitch
    Sleep (100)
WEnd
;===================
;MAIN LOOP
;===================



Func init ()
    Opt ('GUIOnEventMode',1)

    $hWnd = GUICreate ('Main',$width,$height,0,0,$style,$exstyle)
    GUISetOnEvent (-3,'quit',$hWnd)
    GUISetState (@SW_SHOW,$hWnd)

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    $hBB_BMP = _GDIPlus_BitmapCreateFromGraphics ($width,$height,$hGraphic)
    $hBB_Graphic = _GDIPlus_ImageGetGraphicsContext ($hBB_BMP)
    $hBlack = _GDIPlus_BrushCreateSolid ('0xFF' & $Black)
    $hBlue = _GDIPlus_BrushCreateSolid ('0x90' & $Blue)
    $hRed = _GDIPlus_BrushCreateSolid ('0x90' & $Red)
    $hWhite = _GDIPlus_BrushCreateSolid ('0xFF' & $White)

    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ('Tahoma')
    $hFont = _GDIPlus_FontCreate ($hFamily, 20, 1)


    $State = 'main'


    GUIRegisterMsg(0xF, 'MY_PAINT')
    GUIRegisterMsg(0x85, 'MY_PAINT')
    AdlibRegister ('BUFFER',$Buffer_Speed)
EndFunc

Func main ()
    draw_main ()
    While $State = 'main'
        If _IsPressed ('26') Or _IsPressed ('28') Then
            If _IsPressed ('26') Then
                If $key_count = 0 Then
                    $key_count = 2
                Else
                    $key_count -= 1
                EndIf
            EndIf
            If _IsPressed ('28') Then
                If $key_count = 2 Then
                    $key_count = 0
                Else
                    $key_count += 1
                EndIf
            EndIf
            ConsoleWrite ($key_count & @CRLF)
            draw_main ()
        EndIf
        Sleep (100)
    WEnd
EndFunc

Func draw_main ()
    Local $string = 'Use The Arrow Keys To Navigate:' & @CRLF & _
                    'First Choice' & @CRLF & _
                    'Second Choie' & @CRLF & _
                    'Third Choice'
    Local $w = $width/2, $h = $height/2
    Local $tLayout = _GDIPlus_RectFCreate (0,0,$w,$h)
    Local $aInfo = _GDIPlus_GraphicsMeasureString ($hBB_Graphic, $string, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsClear ($hBB_Graphic,'0xFF' & $Black)
    _GDIPlus_GraphicsFillRect ($hBB_Graphic,0,1.1*($key_count+1)*30,$w,35,$hBlue)
    _GDIPlus_GraphicsDrawStringEx ($hBB_Graphic,$string,$hFont,$aInfo[0],$hFormat,$hWhite)
EndFunc

Func quit ()
    AdlibUnRegister ('BUFFER')
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ImageDispose ($hBB_BMP)
    _GDIPlus_GraphicsDispose ($hBB_Graphic)
    _GDIPlus_BrushDispose ($hBlack)
    _GDIPlus_BrushDispose ($hBlue)
    _GDIPlus_BrushDispose ($hRed)
    _GDIPlus_BrushDispose ($hWhite)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)

    _GDIPlus_Shutdown ()
    Exit
EndFunc



Func BUFFER ()
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBB_BMP, 0, 0)
EndFunc
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hWnd,Default,Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    Return $GUI_RUNDEFMSG
EndFunc
Posted (edited)

lo Cody , im fairly new to autoit so i can't offer much help but i've gotten help before on a gdi issue, winapi is used maybe it could help..

Edited by katoNkatoNK
Posted

its probably just a small detail or a timing issue for me... i just can't find it. :huh2:

Posted

Disable the AdlibRegister ('BUFFER',$Buffer_Speed) line and

add the line _GDIPlus_GraphicsDrawImage($hGraphic, $hBB_BMP, 0, 0) to the function Func draw_main () before the EndFunc line!

AdlibRegister() runs asynchrone with the other loop!

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Hmmm.. Ill try that. My script has multiple functions like main. So maybe i CAN grt rid of the buffer. Ill get back to you after im done testing.

Edit:

Awesome it worked perfectly... Solved both the issues!

Yet again... You save the day!

Edited by CodyBarrett

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
  • Recently Browsing   0 members

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