Blaxxun Posted February 28, 2023 Posted February 28, 2023 Hello Forum, As the title says I would like to know how to update the standard GUI elements so that they are in the foreground again after a GDI+ drawing operation. GDI+ uses my whole window and unfortunately overdraws the standard GUI elements. I could of course limit the GDI+ area. But I would be interested in how I can solve this without restrictions by overlaying the standard GuiCtrl elements over the gdi+. Is this possible? expandcollapse popup; ******************************************************************** ; Smart Meter GUI v0.1 by Chris D. ; ; Smart-Meter Data Extract from Website (Done but not integrated yet) ; Smart-Meter Data load from CSV ; Smart-Meter Data Display ; ; A day in 15 minutes intervals = 96 bars in kWh ; ******************************************************************** #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $hGUI, $hGra, $hBru, $hPen ; Bar Chart Global $aCSV ; CSV Array Global $iDay = 0 ; Current Day $aCSV = ReadCSVfromFile() $hGUI = GUICreate("96 Bars Chart", 1600, 800, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP, $WS_SIZEBOX)) $BTN1 = GUICtrlCreateButton("Next", 10, 10, 75, 25) GUISetState() _GDIPlus_Startup() $hGra = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Graphics Object $hBru = _GDIPlus_BrushCreateSolid(0xFFA0A0A0) ; Set Colour for Fill $hPen = _GDIPlus_PenCreate(0xFF000000, 1) ; Set Colour for Outline DrawBars(700, 300, 20) ; Main loop to handle GUI events While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE OnExit() Case $GUI_EVENT_MINIMIZE DrawBars(700, 300, 20) Case $GUI_EVENT_MAXIMIZE DrawBars(700, 300, 20) Case $GUI_EVENT_RESIZED DrawBars(700, 300, 20) Case $GUI_EVENT_RESTORE DrawBars(700, 300, 20) Case $BTN1 $iDay += 96 DrawBars(700, 300, 20) EndSwitch WEnd Func ReadCSVfromFile() Local $sPath = @ScriptDir ; Pfad Local $sFile = "SmartMeter.csv" ; Dateiname Local $sFull = $sPath & "\" & $sFile ; Voller Dateipfad Local $sText = StringStripWS(FileRead($sFull), 7) ; Load File & strip leading, trailing and double white spaces between words Local $a__1D = StringSplit($sText, @CRLF, 2) ; Split Rows into Array Local $iLen = UBound($a__1D) ; Lenght of Array Local $a__2D[$iLen][3] ; 2D Array initialize Local $aTemp For $i = 0 To $iLen - 1 $aTemp = StringSplit($a__1D[$i], ",", 2) ; Split CSV Colums into Array 1by1 Row $a__2D[$i][0] = $aTemp[0] $a__2D[$i][1] = $aTemp[1] $a__2D[$i][2] = $aTemp[2] Next Return $a__2D EndFunc ;==>ReadCSVfromFile Func DrawBars($y, $heightMax, $heightMin) _GDIPlus_GraphicsClear ( $hGra, 0xFFFFFFFF) _GDIPlus_GraphicsDispose($hGra) ; Graphics Object delete $hGra = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Graphics Object create with current Window Size Local $ClSi = WinGetClientSize($hGUI) ; Client Size Local $toWi = $ClSi[0] ; Total Width Local $bCnt = 96 ; Bar Amount Local $bMar = 8 ; Bar Margin Local $barW = Floor($toWi / $bCnt) - $bMar ; Bar Width Local $startX = Floor(($toWi - (($barW + $bMar) * $bCnt - $bMar)) / 2) ; Starting x position of bars Local $i, $barH, $x Local $iNR = 0 _GDIPlus_GraphicsDrawString($hGra, $aCSV[$iDay][0], 800, 10, Default, 7) For $i = 1 To $bCnt ;$barH = Floor(Random($heightMin, $heightMax * 0.8)) $barH = StringReplace($aCSV[($iDay + $i) - 1][2], " kWh", "") * 2000 ; " kWh" aus String entfernen damit Wert übrigbleibt $x = $startX + ($barW + $bMar) * ($i - 1) _GDIPlus_GraphicsFillRect($hGra, $x, $y - $barH, $barW, $barH, $hBru) _GDIPlus_GraphicsDrawRect($hGra, $x, $y - $barH, $barW, $barH, $hPen) _GDIPlus_GraphicsDrawString($hGra, $i, $x, $y + 10, Default, 7) Next ;_WinAPI_RedrawWindow($hGUI) ; DOES refresh but in the wrong order EndFunc ;==>DrawBars Func OnExit() _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBru) _GDIPlus_GraphicsDispose($hGra) _GDIPlus_Shutdown() Exit EndFunc ;==>OnExit SmartMeter.csv
AndyG Posted March 1, 2023 Posted March 1, 2023 (edited) Hi, you could replace the line _WinAPI_RedrawWindow($hGUI) with GUICtrlSetState($BTN1,$GUI_SHOW) to show the Control after displaying the GDI(+)-stuff or use _WinAPI_RedrawWindow($hGUI,0,0,$RDW_INVALIDATE + $RDW_ALLCHILDREN) Edited March 1, 2023 by AndyG SkysLastChance 1
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