Notniat Posted October 24, 2012 Share Posted October 24, 2012 (edited) Hey guys, so I wrote the following code to generate a graph dependant on your latency to a server, but I just can't seem to figure out how to clean old lines without disposing my whole window? Thanks for the help guys Regard expandcollapse popup#include <GDIPlus.au3> #include <WinAPI.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> _GDIPlus_Startup() $kPen = _GDIPlus_PenCreate() $greenPen = _GDIPlus_PenCreate(0xFF667F00) $redPen = _GDIPlus_PenCreate(0xFFE53C36) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 20, 2) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) $Display = GUICreate("temptext", 200, 110, @DesktopWidth / 2, @DesktopHeight / 2, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST) GUISetBkColor(0x010101, $Display) ;GUICtrlCreatePic("", 0, 0, 200, 24, -1, BitOR(0x00100000, 0x00000020)) GUISetState(@SW_SHOW, $Display) _WinAPI_SetLayeredWindowAttributes($Display, 0x010101) $tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display) $ttLayout = _GDIPlus_RectFCreate(50, 50, 50, 50) $c = 0 $sLast = '' $c = 25 ;_GDIPlus_GraphicsFillRect($tGraphic,50,50,50,50) Constants() Func Constants() _GDIPlus_GraphicsClear($tGraphic, 0xFF000FFF) _GDIPlus_GraphicsDispose($tGraphic) $tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display) $ttLayout = _GDIPlus_RectFCreate(50, 50, 50, 50) _GDIPlus_GraphicsDrawLine($tGraphic, 0, 100, 300, 100, $kPen) ; Horisontal axes _GDIPlus_GraphicsDrawLine($tGraphic, 25, 0, 25, 110, $kPen); Vertical axes For $i = 0 To 900 Step 100 _GDIPlus_GraphicsDrawLine($tGraphic, 0, $i / 10, 300, $i / 10, $greenPen) ; Horisontal axes _GDIPlus_GraphicsDrawString($tGraphic, $i, 0, 90 - ($i / 10 - 7)) Next For $i = 45 To 295 Step 20 _GDIPlus_GraphicsDrawLine($tGraphic, $i, 0, $i, 110, $greenPen); Vertical axes Next Global $s = Ping("www.server.com", 1000) ;server IP goes here EndFunc ;==>Constants While 1 $redPen = _GDIPlus_PenCreate(0xFFE53C36) ;_GDIPlus_GraphicsClear($tGraphic, 0xFF000FFF) $ping = Ping("www.PathOfExile.com", 1000) $e = _GDIPlus_GraphicsDrawLine($tGraphic, $c, 100 - $s / 10, $c + 20, 100 - $ping / 10, $redPen); Latency axes $s = $ping $c = $c + 20 ;Sleep(1000) If $c > 175 Then $c = 25 _GDIPlus_PenDispose($redPen) _GDIPlus_GraphicsClear($e) _GDIPlus_GraphicsDispose($e) EndIf WEnd _GDIPlus_PenDispose($kPen) _GDIPlus_GraphicsDispose($tGraphic) _GDIPlus_Shutdown() Edited October 24, 2012 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 24, 2012 Moderators Share Posted October 24, 2012 Notniat,When you post code please use Code tags - put [autoit] before and [/autoit] after your posted code. Then you get a scrolling box as you can see above now I have added the tags. m23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted October 24, 2012 Share Posted October 24, 2012 (edited) I wrote some time ago this one here: expandcollapse popup#include <GDIPlus.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global $iW = 800, $iH = 400 Global $hGui = GUICreate("GDI+ Draw Graph", $iW, $iH) GUISetBkColor(0x000000) GUISetState() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) Global $hPen = _GDIPlus_PenCreate(0xFFFFFF00) Global $hPen2 = _GDIPlus_PenCreate(0xFFFFFFFF, 4) Global $hPen_FG = _GDIPlus_PenCreate(0xFFFFFFFF, 2) Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) Global $iDensity = 0.25, $iAmplitudeMin = 100, $iAmplitudeMax = 300, $iPosX = 10 Global $aCoordinates[Int($iW * $iDensity)][2] Global Const $iUB = UBound($aCoordinates) $aCoordinates[0][0] = 1 Global $b1st = True GUISetOnEvent(-3, "_Exit") Do For $i = 1 To $iUB - 1 DrawBg($hBackbuffer, $iPosX, 0, $iAmplitudeMin, $iW, $iAmplitudeMax - $iAmplitudeMin) $aCoordinates[$i][0] = $i / $iDensity $aCoordinates[$i][1] = Random($iAmplitudeMin, $iAmplitudeMax, 1) _GDIPlus_GraphicsDrawLines($hBackbuffer, $aCoordinates, $hPen) ;~ _GDIPlus_GraphicsFillEllipse($hBackbuffer, $aCoordinates[$i][0] - 4 , $aCoordinates[$i][1] - 4, 8, 8, $hBrush) ;~ _GDIPlus_GraphicsDrawLine($hBackbuffer, $aCoordinates[$i][0] - 1, $iAmplitudeMin, $aCoordinates[$i][0], $iAmplitudeMax, $hPen2) DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $hBackbuffer, "handle", $hPen2, "float", $aCoordinates[$i][0] - 2, "float", $iAmplitudeMin, "float", $aCoordinates[$i][0] - 2, "float", $iAmplitudeMax) _GDIPlus_GraphicsDrawLine($hBackbuffer, 0, $iAmplitudeMin, 0, $iAmplitudeMax, $hPen_FG) _GDIPlus_GraphicsDrawLine($hBackbuffer, 0, $iAmplitudeMax, $iW, $iAmplitudeMax, $hPen_FG) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $iPosX, 0, $iW - $iPosX * 2, $iH) If $i < $iUB And $b1st Then $aCoordinates[0][0] = $i EndIf Sleep(100) Next $b1st = False Until False Func DrawBg(ByRef $hContext, $iLines, $iX, $iY, $iW, $iH) Local $hBrush_BG = _GDIPlus_BrushCreateSolid(0xFF004000) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY, $iW, $iH, $hBrush_BG) Local $hPen_BG = _GDIPlus_PenCreate(0xFF00B000) Local $i, $fStep = $iH / ($iLines - 1) For $i = $iLines To $iH Step $fStep _GDIPlus_GraphicsDrawLine($hContext, 0, $iY + $i, $iW, $iY + $i, $hPen_BG) Next _GDIPlus_PenDispose($hPen_BG) _GDIPlus_BrushDispose($hBrush_BG) EndFunc ;==>DrawBg Func _Exit() _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_PenDispose($hPen_FG) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphics) GUIDelete() Exit EndFunc ;==>_Exit Func _GDIPlus_GraphicsDrawLines($hGraphics, $aPoints, $hPen) Local $iI, $iCount, $pPoints, $tPoints, $aResult $iCount = $aPoints[0][0] $tPoints = DllStructCreate("float[" & $iCount * 2 & "]") $pPoints = DllStructGetPtr($tPoints) For $iI = 1 To $iCount DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1) DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2) Next $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawLines", "handle", $hGraphics, "handle", $hPen, "ptr", $pPoints, "int", $iCount) $tPoints = 0 Return 1 EndFunc ;==>_GDIPlus_GraphicsDrawLines Maybe you can adapt it for your needs. Br, UEZ Edited October 24, 2012 by 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...
trancexx Posted October 24, 2012 Share Posted October 24, 2012 (edited) I have a visually impaired friend using, what I believe is called, NVDA screen reader and I clearly remember him teling me he has big problems here reading text within code tags. Apparently the reader can't read lines correctly because of the style tags. If that, or something similar is the reason Notniat that you don't use code tags when posting, then I apologize in behalf of the forum staff for moderator editing your post. Maybe send short PM to the moderator to avoid that in the future. If it's just your ignorance then forget that I wrote this post and do what he says. Thank you for understanding. Edited October 24, 2012 by trancexx ileandros 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Notniat Posted October 25, 2012 Author Share Posted October 25, 2012 Hey guys, yeah thanks for the help, I apologise for not using the tags, and will defenatly use them in future Thanks for the helps Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 25, 2012 Moderators Share Posted October 25, 2012 Notniat, No need to apologise - but now you (and any other new members reading the thread) now know what to do in future. We did have a visually impaired member a while ago who asked us not to use code tags when replying for the very reasons trancexx mentioned above, but as that was the only case I have come across in my time here I have the default position of suggesting the use of tags (and adding them for long code postings). I am sure that someone who requires the bare text for some good reason will soon tell me, as indeed happened in the case I mentioned. Glad you got your question answered. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Notniat Posted October 25, 2012 Author Share Posted October 25, 2012 Hey UEZ, Thanks for your reply, it has helped in deed, just wondering in general, is there no way of clearing old line drawn? Regards Link to comment Share on other sites More sharing options...
UEZ Posted October 25, 2012 Share Posted October 25, 2012 (edited) No, it is not possible. You must clean the whole graphic handle and redraw the content again or you use several GUI layers for each e.g. pens but that is an overkill. I can remember that on the old good C64 it was possible to move sprites without erasing the background. But time has changed... Br, UEZ Edited October 25, 2012 by 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...
Notniat Posted October 25, 2012 Author Share Posted October 25, 2012 Okay cool.. Thanks for your help man 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