CodyBarrett Posted June 23, 2011 Share Posted June 23, 2011 hey guys, i've got another GDI issue 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. expandcollapse popup#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 [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
katoNkatoNK Posted June 23, 2011 Share Posted June 23, 2011 (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 June 23, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
CodyBarrett Posted June 23, 2011 Author Share Posted June 23, 2011 its probably just a small detail or a timing issue for me... i just can't find it. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
UEZ Posted June 23, 2011 Share Posted June 23, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
CodyBarrett Posted June 24, 2011 Author Share Posted June 24, 2011 (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 June 24, 2011 by CodyBarrett [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now