Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/11/2022 in all areas

  1. This is a UDF to check for running a source file from SciTE with AutoIt3 or directly and determine which one it is: #include <WinAPIProc.au3> If _RunBySciTE() Then MsgBox(0, "Run by SciTE", "This script is ran by SciTE") Else MsgBox(0, "Not Run by SciTE", "This script is not ran by SciTE") EndIf Func _RunBySciTE($iPID = @AutoItPID) Local $n, $iParentPID = $iPID For $n = 1 To 5 If _WinAPI_GetProcessName($iParentPID) = "SciTE.exe" Then Return True $iParentPID = _WinAPI_GetParentProcess($iParentPID) Next Return False EndFunc ;==>_RunBySciTE Jos
    2 points
  2. OverviewFirst part First part of this example was published March/April 2021 and contains these main sections: Simple implementation of a virtual treeview created from data in a source file Multi-line treeview items and a discussion of an example in the help file Other sections about Item images, Performance tests and Treeview structure Second part Second part of the example has started up in January 2023: Updated all first part examples (item param offset, performance optimizations) Short summary of first part and further development of Real virtual treeviews TreeView posts Other posts and examples regarding treeviews: Saving/reading item levels and texts is the starting point for this example Use of colors and fonts in treeview items through custom draw code Virtual treeviews The basic idea behind implementing both a virtual treeview and a virtual listview is to store as much data as possible in the data source and as little data as possible in the treeview and listview. The purpose is especially to performance optimize creation of the treeview and listview. A virtual listview is created with the LVS_OWNERDATA style. To populate listview items and subitems, you respond to LVN_GETDISPINFO notifications contained in WM_NOTIFY messages. A virtual treeview isn't created based on a particular style of the treeview. A virtual treeview is created by setting LPSTR_TEXTCALLBACK and I_CHILDRENCALLBACK values in the TVITEM structure used to create the treeview items. The LPSTR_TEXTCALLBACK and I_CHILDRENCALLBACK values cause TVN_GETDISPINFO notifications (also contained in WM_NOTIFY messages) to be generated. To populate treeview items and child items, you respond to these TVN_GETDISPINFO notifications. Create treeview from data sourceIn the attempt to implement a virtual treeview, the first step is to create the treeview based on a data source e.g. a simple text file. This post demonstrates how to uniquely store a treeview in a text file and then uniquely restore the same treeview. It's sufficient to store treeview item levels and texts. This is a slightly modified version of TreeView.txt: 0|0 0|1 0|2 1|3 1|This 1|is 2|6 2|a 2|very 2|nice 3|10 3|TreeView 0|, (comma) 1|13 1|indeed. 0|15 And a slightly modified version of the code to recreate the treeview (1) Conventional TreeView.au3) #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> Global $hTreeView Example() Func Example() ; Create GUI Local $hGui = GUICreate( "Create Conventional TreeView From File", 400, 300, 600, 300, $GUI_SS_DEFAULT_GUI ) ; Create TreeView Local $idTreeView = GUICtrlCreateTreeView( 4, 4, 392, 292, $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE ) $hTreeView = GUICtrlGetHandle( $idTreeView ) ; Read level and text of TreeView items and create TreeView CreateTreeView( FileReadToArray( "TreeView.txt" ) ) ; Show GUI GUISetState( @SW_SHOW, $hGui ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete( $hGui ) EndFunc ; Create conventional TreeView Func CreateTreeView( $aItems ) ; TreeView item information Local $aItem, $hItem ; TreeView level information Local $aLevels[100], $iLevel = 0, $iLevelPrev = 0 ; $aLevels[$iLevel] contains the last item of that level ; Add TreeView root $aItem = StringSplit( $aItems[0], "|", 2 ) $hItem = _GUICtrlTreeView_Add( $hTreeView, 0, $aItem[1] ) $aLevels[$iLevel] = $hItem ; Add TreeView items For $i = 1 To UBound( $aItems ) - 1 $aItem = StringSplit( $aItems[$i], "|", 2 ) $iLevel = $aItem[0] If $iLevel <> $iLevelPrev Then $hItem = $iLevel > $iLevelPrev ? _GUICtrlTreeView_AddChild( $hTreeView, $aLevels[$iLevelPrev], $aItem[1] ) _ ; A child of the previous level : _GUICtrlTreeView_Add( $hTreeView, $aLevels[$iLevel], $aItem[1] ) ; A sibling of the level $iLevelPrev = $iLevel Else ; $iLevel = $iLevelPrev $hItem = _GUICtrlTreeView_Add( $hTreeView, $aLevels[$iLevel], $aItem[1] ) ; A sibling of the level EndIf $aLevels[$iLevel] = $hItem Next ; $aLevels[$iLevel] contains the last item of that level ; Expand all child items _GUICtrlTreeView_Expand( $hTreeView ) EndFunc Reduced and optimized functionIn the CreateTreeView() function at bottom of the code above, the treeview is created using _GUICtrlTreeView_Add() and _GUICtrlTreeView_AddChild() from GuiTreeView.au3. Both of these functions executes __GUICtrlTreeView_AddItem(), which is an internal function. This internal function fills the TVITEM structures where you can set the LPSTR_TEXTCALLBACK and I_CHILDRENCALLBACK values. The second step is to reduce and optimize the code in CreateTreeView() so that the TVITEM structure is filled in directly in this function. This is the reduced and optimized function (2) Optimized TreeView.au3) ; Create TreeView with optimized code Func CreateTreeView( $aItems ) ; TreeView item information Local $aItem ; TreeView level information Local $aLevels[100][2], $iLevel = 0, $iLevelPrev = 0 ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level ; TreeView text buffer Local $iBuffer, $tBuffer = DllStructCreate( "wchar Text[50]" ), $pBuffer = DllStructGetPtr( $tBuffer ) ; TreeView insert structure Local $tInsert = DllStructCreate( $tagTVINSERTSTRUCT ), $pInsert = DllStructGetPtr( $tInsert ) DllStructSetData( $tInsert, "InsertAfter", $TVI_LAST ) DllStructSetData( $tInsert, "Mask", $TVIF_TEXT ) DllStructSetData( $tInsert, "Text", $pBuffer ) ; Add TreeView root $aItem = StringSplit( $aItems[0], "|", 2 ) $iBuffer = 2 * StringLen( $aItem[1] ) + 2 DllStructSetData( $tBuffer, "Text", $aItem[1] ) DllStructSetData( $tInsert, "TextMax", $iBuffer ) $aLevels[$iLevel][1] = NULL DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) ; Add TreeView items For $i = 1 To UBound( $aItems ) - 1 $aItem = StringSplit( $aItems[$i], "|", 2 ) $iBuffer = 2 * StringLen( $aItem[1] ) + 2 DllStructSetData( $tBuffer, "Text", $aItem[1] ) DllStructSetData( $tInsert, "TextMax", $iBuffer ) $iLevel = $aItem[0] If $iLevel <> $iLevelPrev Then $aLevels[$iLevel][1] = $iLevel > $iLevelPrev ? $aLevels[$iLevelPrev][0] _ ; A child of the previous level : GUICtrlSendMsg( $idTreeView, $TVM_GETNEXTITEM, $TVGN_PARENT, $aLevels[$iLevel][0] ) ; A sibling of the level $iLevelPrev = $iLevel EndIf DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) Next ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level ; Expand all child items _GUICtrlTreeView_Expand( $hTreeView ) EndFunc Semi-virtual treeviewThe third step is to implement a semi-virtual treeview, where only the tree structure itself but not the item texts are created in CreateTreeView(). Instead of filling in the texts, we set the LPSTR_TEXTCALLBACK value in the TVITEM structure. And then we fill in the texts as needed through a WM_NOTIFY message handler and TVN_GETDISPINFO notifications (3) Semi-Virtual TreeView.au3) ; Create TreeView structure Func CreateTreeView( $aItems ) ; TreeView level information Local $aLevels[100][2], $iLevel = 0, $iLevelPrev = 0 ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level ; TreeView insert structure Local $tInsert = DllStructCreate( $tagTVINSERTSTRUCT ), $pInsert = DllStructGetPtr( $tInsert ) DllStructSetData( $tInsert, "InsertAfter", $TVI_LAST ) DllStructSetData( $tInsert, "Mask", $TVIF_HANDLE+$TVIF_PARAM+$TVIF_TEXT ) DllStructSetData( $tInsert, "Text", -1 ) ; $LPSTR_TEXTCALLBACK ; Add TreeView root $aLevels[$iLevel][1] = Ptr(0) DllStructSetData( $tInsert, "Param", 0 ) DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) ; Add TreeView items For $i = 1 To UBound( $aItems ) - 1 $iLevel = StringSplit( $aItems[$i], "|", 2 )[0] If $iLevel <> $iLevelPrev Then $aLevels[$iLevel][1] = $iLevel > $iLevelPrev ? $aLevels[$iLevelPrev][0] _ ; A child of the previous level : GUICtrlSendMsg( $idTreeView, $TVM_GETNEXTITEM, $TVGN_PARENT, $aLevels[$iLevel][0] ) ; A sibling of the level $iLevelPrev = $iLevel EndIf DllStructSetData( $tInsert, "Param", $i ) DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) Next ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level ; Expand all child items _GUICtrlTreeView_Expand( $hTreeView ) EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Switch HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Case $hTreeView Switch DllStructGetData( $tNMHDR, "Code" ) Case $TVN_GETDISPINFOW ; Display TreeView item text Local Static $tBuffer = DllStructCreate( "wchar Text[50]" ), $pBuffer = DllStructGetPtr( $tBuffer ) Local $tDispInfo = DllStructCreate( $tagNMTVDISPINFO, $lParam ), $sText = StringSplit( $aItems[DllStructGetData($tDispInfo,"Param")], "|", 2 )[1] DllStructSetData( $tBuffer, "Text", $sText ) DllStructSetData( $tDispInfo, "Text", $pBuffer ) DllStructSetData( $tDispInfo, "TextMax", 2 * StringLen( $sText ) + 2 ) EndSwitch EndSwitch #forceref $hWnd, $iMsg, $wParam EndFunc Note that this reduces and optimizes the code in CreateTreeView() even more because the buffer for text strings is no longer needed. Instead, the buffer is populated in the WM_NOTIFY message handler. This technique has the great advantage that only visible treeview items are filled with text strings. Because item texts are only filled in when the items are visible in the treeview, it's necessary to establish a connection between the treeview items and the data source that contains the texts. The data source, which is a simple text file, is loaded into an array. The connection between a treeview item and the data source is the index in this array. Therefore, the array index is stored in the Param field of the TVITEM structure. Virtual treeviewTo make the treeview completely virtual, the fourth and final step is to create and display child items only when required. That is, when an end user clicks the expand button to the left of a treeview item that actually contains child items. And only direct children of this item will be created. If an end user doesn't click an expand button (because these child items are not the ones he's looking for), the child items in question will not be created in the tree structure at all. To make the treeview completely virtual only first level (level-0) items are created in CreateTreeView(). Instead of creating child items, we set the I_CHILDRENCALLBACK value in the TVITEM structure. And then we create child items as needed through a WM_NOTIFY message handler and TVN_GETDISPINFO and TVN_ITEMEXPANDING notifications (4) Virtual TreeView.au3) ; Create TreeView structure Func CreateTreeView( $aLevel0 ) ; TreeView insert structure Local $tInsert = DllStructCreate( $tagTVINSERTSTRUCT ), $pInsert = DllStructGetPtr( $tInsert ) DllStructSetData( $tInsert, "InsertAfter", $TVI_LAST ) DllStructSetData( $tInsert, "Mask", $TVIF_CHILDREN+$TVIF_HANDLE+$TVIF_PARAM+$TVIF_TEXT ) DllStructSetData( $tInsert, "Parent", NULL ) DllStructSetData( $tInsert, "Children", -1 ) ; $I_CHILDRENCALLBACK DllStructSetData( $tInsert, "Text", -1 ) ; $LPSTR_TEXTCALLBACK ; Add TreeView items For $i = 0 To UBound( $aLevel0 ) - 1 DllStructSetData( $tInsert, "Param", $aLevel0[$i] ) GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) Next EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Switch HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Case $hTreeView Switch DllStructGetData( $tNMHDR, "Code" ) Case $TVN_GETDISPINFOW ; Display TreeView item text Local Static $tBuffer = DllStructCreate( "wchar Text[50]" ), $pBuffer = DllStructGetPtr( $tBuffer ) Local $tDispInfo = DllStructCreate( $tagNMTVDISPINFO, $lParam ), $iIndex = DllStructGetData( $tDispInfo, "Param" ), $sText = StringSplit( $aItems[$iIndex], "|", 2 )[3] DllStructSetData( $tBuffer, "Text", $sText ) DllStructSetData( $tDispInfo, "Text", $pBuffer ) DllStructSetData( $tDispInfo, "TextMax", 2 * StringLen( $sText ) + 2 ) DllStructSetData( $tDispInfo, "Children", StringSplit( $aItems[$iIndex], "|", 2 )[1] = 0 ? 0 : 1 ) Case $TVN_ITEMEXPANDINGW ; Create TreeView structure for childs Local $tTreeView = DllStructCreate( $tagNMTREEVIEW, $lParam ) If BitAND( DllStructGetData( $tTreeView, "Action" ), $TVE_EXPAND ) <> $TVE_EXPAND _ Or Int( StringSplit( $aItems[DllStructGetData($tTreeView,"NewParam")], "|", 2 )[2] ) Then Return ; TreeView insert structure Local $tInsert = DllStructCreate( $tagTVINSERTSTRUCT ), $pInsert = DllStructGetPtr( $tInsert ) DllStructSetData( $tInsert, "InsertAfter", $TVI_LAST ) DllStructSetData( $tInsert, "Mask", $TVIF_CHILDREN+$TVIF_HANDLE+$TVIF_PARAM+$TVIF_TEXT ) DllStructSetData( $tInsert, "Parent", DllStructGetData( $tTreeView, "NewhItem" ) ) DllStructSetData( $tInsert, "Children", -1 ) ; $I_CHILDRENCALLBACK DllStructSetData( $tInsert, "Text", -1 ) ; $LPSTR_TEXTCALLBACK ; Add TreeView children Local $iNewIndex = DllStructGetData( $tTreeView, "NewParam" ) + 1 For $i = 0 To StringSplit( $aItems[$iNewIndex-1], "|", 2 )[1] - 1 DllStructSetData( $tInsert, "Param", $iNewIndex + $i ) GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) Next ; Indicate that children have been added $aItems[$iNewIndex-1] = StringReplace( $aItems[$iNewIndex-1], 7, "1" ) EndSwitch EndSwitch #forceref $hWnd, $iMsg, $wParam EndFunc Creating only first level (level-0) items in CreateTreeView() is the crucial step that truly optimizes creation of the treeview. CreateTreeView() in this version is very simple and fast. $aLevel0 is an index of first level (level-0) items. To handle TVN_GETDISPINFO and TVN_ITEMEXPANDING notifications regarding child items, more information is needed in the source file (TreeView-4.txt) 0|000|0|0 0|000|0|1 0|003|0|2 1|000|0|3 1|000|0|This 1|004|0|is 2|000|0|6 2|000|0|a 2|000|0|very 2|002|0|nice 3|000|0|10 3|000|0|TreeView 0|002|0|, (comma) 1|000|0|13 1|000|0|indeed. 0|000|0|15 It's the number of child items in the second field, and a flag to indicate whether child items have already been created in the third field. At top of the TVN_ITEMEXPANDING code section, it's checked if a treeview item with child items is expanded or collapsed and if these child items are already created: Case $TVN_ITEMEXPANDINGW ; Create TreeView structure for childs Local $tTreeView = DllStructCreate( $tagNMTREEVIEW, $lParam ) If BitAND( DllStructGetData( $tTreeView, "Action" ), $TVE_EXPAND ) <> $TVE_EXPAND _ Or Int( StringSplit( $aItems[DllStructGetData($tTreeView,"NewParam")], "|", 2 )[2] ) Then Return The rest of the code in the TVN_ITEMEXPANDING section creates the child items. This code is again very simple and fast. 100,000 items5) 100,000 Items.au3 creates a virtual treeview with 100,000 items based on the 100,000.txt source file. Of course, creating the treeview is lightning fast. 7z-fileThe 7z-file contains source code for UDFs and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. VirtualTreeView.7z
    1 point
  3. Last Updated: 20/02/2010 Hi! A while back I created a Graph UDF to enable drawing of graphs in a GUI-control-style way. I've converted that UDF to use GDI+ to take advantage of double-buffering. Functions: _GraphGDIPlus_Create - create graph area _GraphGDIPlus_Delete - delete graph & shutdown GDI+ _GraphGDIPlus_Clear - clear current drawings _GraphGDIPlus_Set_RangeX - set x axis range _GraphGDIPlus_Set_RangeY - set y axis range _GraphGDIPlus_Set_PenColor - set color of line _GraphGDIPlus_Set_PenSize - set line width _GraphGDIPlus_Set_PenDash - set line dash style _GraphGDIPlus_Set_GridX - add grid (x ticks) _GraphGDIPlus_Set_GridY - add grid (y ticks) _GraphGDIPlus_Plot_Start - define starting position _GraphGDIPlus_Plot_Line - plot line _GraphGDIPlus_Plot_Point - plot a small square _GraphGDIPlus_Plot_Dot - plot a single pixel _GraphGDIPlus_Refresh - refresh graph area (draw) NOTES / UPDATES: - be aware that "WM_ACTIVATE" is registered in_GraphGDIPlus_Create (this allows redrawing of the GDI+ when mini/maximizing the GUI) - due to a hideous over-sight on my part, I've had to update the way that "WM_ACTIVATE" is registered by using a global var in the UDF... so DON'T use "$aGraphGDIPlusaGraphArrayINTERNAL" in your script pls!! (couldn't think of any other way to do this) - be aware that WinSetTrans($hWnd,"",255) is called in _GraphGDIPlus_Create (this prevents GDI+ glitches when moving GUI) - _GraphGDIPlus_Delete must be called upon GUI exit (it shuts down GDI+, and disposes of pens etc) - Using _GraphGDIPlus_Clear will remove grid-lines too. You will need to redraw these using _GraphGDIPlus_Set_Grid... after clearing - updated to allow setting color of the x=0 and y=0 lines when visible (when using -ve and +ve axes) - updated to allow user to decide whether to shut down GDI+ completely when deleting the graph (you may have your own graphics etc) - updated to declare all vars as Local in functions. Sorry if you had problems with this, no excuses, entirely my fault. - updated to clean up pen use - be aware that "WM_MOVE" is registered in_GraphGDIPlus_Create (this allows redrawing of the GDI+ when moving the GUI) The updates should NOT be script breaking, unless you are manually using Pen vars/handles from the returned graph array. TO DO - Look at adding a "save image as..." option (suggested by UEZ - thanks!) - Error checking / returns ???? any suggestions ???? Example Use This graph draws Gamma Function in real-time... #include "GraphGDIPlus.au3" Opt("GUIOnEventMode", 1) $GUI = GUICreate("",600,600) GUISetOnEvent(-3,"_Exit") GUISetState() ;----- Create Graph area ----- $Graph = _GraphGDIPlus_Create($GUI,40,30,530,520,0xFF000000,0xFF88B3DD) ;----- Set X axis range from -5 to 5 ----- _GraphGDIPlus_Set_RangeX($Graph,-5,5,10,1,1) _GraphGDIPlus_Set_RangeY($Graph,-5,5,10,1,1) ;----- Set Y axis range from -5 to 5 ----- _GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE) _GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE) ;----- Draw the graph ----- _Draw_Graph() While 1 Sleep(100) WEnd Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True For $i = -5 to 5 Step 0.005 $y = _GammaFunction($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Func _GammaFunction($iZ) $nProduct = ((2^$iZ) / (1 + $iZ)) For $n = 2 to 1000 $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n)) Next Return (1/$iZ) * $nProduct EndFunc Func _Exit() ;----- close down GDI+ and clear graphic ----- _GraphGDIPlus_Delete($GUI,$Graph) Exit EndFunc UDF: GraphGDIPlus.au3 Updated 20/02/2010 ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# =============================================================================== ; Title .........: GraphGDIPlus ; AutoIt Version: 3.3.0.0+ ; Language: English ; Description ...: A Graph control to draw line graphs, using GDI+, also double-buffered. ; Notes .........: ; ======================================================================================= ; #VARIABLES/INCLUDES# ================================================================== #include-once #include <GDIplus.au3> Global $aGraphGDIPlusaGraphArrayINTERNAL[1] ; ======================================================================================= ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd, $iLeft, $iTop, $iWidth, $iHeight, $hColorBorder = 0xFF000000, $hColorFill = 0xFFFFFFFF, $iSmooth = 2) Local $graphics, $bitmap, $backbuffer, $brush, $bpen, $gpen, $pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- ;WinSetTrans($hWnd, "", 255) - causes problems when more than 2 graphs used ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $graphics);buffer bitmap $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, $iSmooth) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $iWidth, $iHeight, $brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen, $GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen, $GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen, $GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer, 0, 0, $iWidth, $iHeight, $pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, $iLeft, $iTop, $iWidth + 1, $iHeight + 1) ;----- register redraw ----- GUIRegisterMsg(0x0006, "_GraphGDIPlus_ReDraw") ;0x0006 = win activate GUIRegisterMsg(0x0003, "_GraphGDIPlus_ReDraw") ;0x0003 = win move ;----- prep + load array ----- Dim $aGraphArray[24] = ["", $graphics, $iLeft, $iTop, $iWidth, $iHeight, 0, 1, 0, 1, _ $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $hColorBorder, $hColorFill, _ $bitmap, $backbuffer, 0, 0, $pen, $brush, $bpen, $gpen] ;----- prep re-draw array for all graphs created ----- ReDim $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) + 1] $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1] = $aGraphArray Return $aGraphArray EndFunc ;==>_GraphGDIPlus_Create Func _GraphGDIPlus_ReDraw($hWnd) ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- Local $i _WinAPI_RedrawWindow($hWnd, 0, 0, 0x0100) For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 If $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Then ContinueLoop _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL[$i]) Next EndFunc ;==>_GraphGDIPlus_ReDraw ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd, ByRef $aGraphArray, $iKeepGDIPlus = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $i, $aTemp ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[17]) _GDIPlus_BitmapDispose($aGraphArray[16]) _GDIPlus_GraphicsDispose($aGraphArray[1]) _GDIPlus_BrushDispose($aGraphArray[21]) _GDIPlus_PenDispose($aGraphArray[20]) _GDIPlus_PenDispose($aGraphArray[22]) _GDIPlus_PenDispose($aGraphArray[23]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- remove form global redraw array ----- For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 $aTemp = $aGraphGDIPlusaGraphArrayINTERNAL[$i] If IsArray($aTemp) = 0 Then ContinueLoop If $aTemp[1] = $aGraphArray[1] Then $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Next ;----- close array ----- $aGraphArray = 0 EndFunc ;==>_GraphGDIPlus_Delete ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- Set background Color ----- _GDIPlus_GraphicsFillRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[21]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) EndFunc ;==>_GraphGDIPlus_Clear ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1], $aGraphArray[16], $aGraphArray[2], _ $aGraphArray[3], $aGraphArray[4] + 1, $aGraphArray[5] + 1) EndFunc ;==>_GraphGDIPlus_Refresh ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray, $iLow, $iHigh, $iXTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $i ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("", (($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5], 1, 5) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10, $aGraphArray[4] / $iXTicks, 13, 1) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", (($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ;==>_GraphGDIPlus_Set_RangeX ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray, $iLow, $iHigh, $iYTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksY, $ahTicksLabelsY, $i ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)), 5, 1) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6, 30, 13, 2) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i], StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)), $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ;==>_GraphGDIPlus_Set_RangeY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- MOVE pen to start point ----- $aGraphArray[18] = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $aGraphArray[19] = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) EndFunc ;==>_GraphGDIPlus_Plot_Start ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], $aGraphArray[18], $aGraphArray[19], $iX, $iY, $aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Line ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX-1, $iY-1, 2, 2, $aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Point ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX, $iY, 1, 1, $aGraphArray[20]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Dot ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray, $hColor) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[20], $hColor) EndFunc ;==>_GraphGDIPlus_Set_PenColor ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray, $iSize = 1) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[20], $iSize) EndFunc ;==>_GraphGDIPlus_Set_PenSize ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray, $iDash = 0) If IsArray($aGraphArray) = 0 Then Return Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[20], $Style) EndFunc ;==>_GraphGDIPlus_Set_PenDash ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorY0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridX ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorX0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[22]) ;draw border EndFunc ;==>_GraphGDIPlus_RedrawRect ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType, $iValue, $iLow, $iHigh, $iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow))))) Case "p" Return ($iValue / ($iTotalPixels / ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ;==>_GraphGDIPlus_Reference_Pixel Thanks To: joseLB for looking at adding grid lines in the original UDF monoceres for the e-x-c-e-l-l-e-n-t GDI+ double buffer template UEZ for suggesting anti-aliasing (now included by default) winux38 for pointing out an error
    1 point
  4. A possible change in search code : ; _GUICtrlTreeView_Expand($idTreeView, $aPath[$i][1], True) _GUICtrlTreeView_EnsureVisible($hTreeView, $aPath[$i][1]) For example, a search on "abv" would unnecessarily expand the 3rd match like this : Instead of the following (which seems more correct) : I just discovered that OP's original code was based on LarsJ's thread ("3) Semi-Virtual TreeView.au3") His examples 4) and 5) look very interesting, making the TreeView virtual. Nearly same code in 4) and 5) , except 5) uses a 100.000 rows text file. As I never approached the TreeView control (until the current thread) then it's time to begin
    1 point
  5. Have you tried using Hotkeys? I don't have this program, However, you can give this a try to create a new report. ControlSend("Report Builder", "", "",("^n")) Just noticed you said that the mouse did no ove when you tried MouseClick() Do you get a message box that says "test" when you run this? AutoItSetOption("MouseCoordMode",0) WinWait("Report Builder") WinActivate("Report Builder") Msgbox(0,"","test") MouseClick("primary", 25, 67, 1, 20) If no your Winwait() is not finding anything.
    1 point
  6. I tried it but it doesn't work. I do believe that the scroll bars are not standard Window elements (like pretty much everything else in Chrome). Thanks for the tip. As you can see, I am not a JS wizard...
    1 point
  7. @NineYou could use an array to eliminate the repeated calls to _WD_ExecuteScript -- $sScript = "return new Array(document.documentElement.scrollTop, screen.height, document.body.scrollHeight, window.innerHeight);" $aResults = _WD_ExecuteScript($sSession, $sScript, $_WD_EmptyDict, Default, $_WD_JSON_Value) I'm wondering if this could be done with one of the _GuiScrollBars functions.
    1 point
  8. When posting scripts to platforms that use different tab settings (e.g. GitHub), they are ripped from their formatting. Thus, it is better to replace all tabs with spaces in the correct position before posting. I have created the following Lua script for this purpose. It replaces all tabs with the appropriate number of spaces in the document opened in SciTE. By default a tab width of 4 characters is used. But other values are also possible, details about this and the installation and usage are at the beginning of the script. -- TIME_STAMP 2022-05-01 11:28:55 v 0.1 --[[ == Installation == • Store the file to "YOUR-PATH/TabReplaceSciTE.lua" • New entry in your "SciTEUser.properties" (find a free command number, in example is "49" used, and a free shortcut) #49 Replace TAB with spaces command.name.49.*=Replace TAB with spaces command.49.*=dofile "YOUR-PATH/TabReplaceSciTE.lua" command.mode.49.*=subsystem:lua,savebefore:no command.shortcut.49.*=Ctrl+Alt+Shift+R • If your sources has different values for TAB width, you can modify the command call in this script (last line), "TabReplace_FileInSciTE(2)" or "TabReplace_FileInSciTE(8)". Or add a property to your "SciTEUser.properties" to have more flexibility: # The currently used tab.size, which is replaced by spaces # Without this property or with empty value "4" is used. tab.replace.width=2 Then change the last line in this script to: TabReplace_FileInSciTE(props['tab.replace.width']) == Usage == • Open any script. • Hit the shortcut. • In the opened document, all TAB will be replaced by the number of spaces corresponding to the TAB position in the line. ]] ---------------------------------------------------------------------------------------------------- --[[ in...: _line A line of text whose TAB are to be replaced by spaces. .....: _tabsize TAB size in number of characters. If it is omitted, 4 is used. out..: The line, with TAB replaced if necessary, and the number of replacements. ]] ---------------------------------------------------------------------------------------------------- TabReplace_Line = function(_line, _tabsize) if _line:find('^[\r\n]+$') then return _line, 0 end -- only a line break if _line == '' then return _line, 0 end -- only a empty string local posTab = _line:find('\t') if posTab == nil then return _line, 0 end -- no TAB included _tabsize = _tabsize or 4 -- default TAB width local tTab, s, sRep, iLen, sumLen = {}, ' ', '', 0, 0 while posTab ~= nil do -- calculation replacement string, taking into account characters to be inserted iLen = (_tabsize - ((posTab + sumLen -1) % _tabsize)) sumLen = sumLen + iLen -1 -- total length of the replacements sRep = s:rep(iLen) -- create replacement string table.insert(tTab, sRep) -- save to table posTab = _line:find('\t', posTab +1) -- find next TAB end local idx = 0 _line = _line:gsub('\t', function() idx = idx +1 return tTab[idx] end) return _line, idx end ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- --[[ Replaces all TAB in the file currently open in SciTE ]] ---------------------------------------------------------------------------------------------------- TabReplace_FileInSciTE = function(_tabsize) local caret = editor.CurrentPos local fvl = editor.FirstVisibleLine local content = '' if _tabsize == '' then _tabsize = nil end for i=0, editor.LineCount -1 do local line = editor:GetLine(i) line = line or '' line = TabReplace_Line(line, _tabsize) content = content..line end editor:BeginUndoAction() editor:ClearAll() editor:InsertText(0, content) editor:EndUndoAction() editor.CurrentPos = caret editor:SetSel(caret, caret) editor.FirstVisibleLine = fvl end ---------------------------------------------------------------------------------------------------- TabReplace_FileInSciTE(4) -- If required: Change the TAB size here TabReplaceSciTE.lua
    1 point
  9. LarsJ has a good example for coloring the items. Maybe can be referred.
    1 point
×
×
  • Create New...