Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/08/2013 in all areas

  1. 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
  2. eynstyne

    MIDI UDF

    From previous posts, I have been working long and hard on thie UDF, but it has turned out a success. Unlike people who do not want to share UDF's [Phillip Benefall], I will be completely willing to give this UDF for download. See the example in the UDF file, actually, you can just run the UDF and listen to the music... Eynstyne MIDI UDF!!! - Midiudf.au3 (Stream functions still need work...) If there are any problems with the UDF, PM me THX Enjoy!
    1 point
  3. Kilmatead

    _GetReparseTarget

    ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetReparseTarget ; Description....: Resolves a Reparse-Point (Junction, Symbolic Link or Mount Point) to its target and returns that destination path ; Syntax.........: _GetReparseTarget ( $sLink[, $AbsPath = True] ) ; Parameters.....: $sLink - Full path to a Reparse-Point object ; $AbsPath - Return an absolute path when link ID type is 2 (embedded relative path Symbolic Link) ; ; Return values..: Success - The path/filename of the target location ; ; @extended returns the ID/type of the Reparse-Point itself: ; 0 - Unknown/Unresolved ; 1 - Symbolic Link (embedded Absolute-Path) ; 2 - Symbolic Link (embedded Relative-Path) - primary return value will be an absolute path via the $sLink container (set $AbsPath = False to return the relative path) ; 3 - Junction Point ; 4 - Mount Point - primary return value will be the Globally Unique Identifier (GUID) as \\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\ ; ; Failure - Empty string ("") and sets the @error flag: ; 1 - $sLink Not Found ; 2 - Unable to Open $sLink ; 3 - $sLink is not a Reparse-Point ; 4 - Unresolveable (Corrupted Tag / No Target details) ; ; Author.........: Kilmatead ; Modified.......: ; Remarks........: @Extended may still contain a valid ID even if the link itself failed resolution ; ; The $AbsPath parameter has no effect beyond relative path Symbolic Links (ID 2) ; ; No check is made to see if the resolved target folder or file actually exists, as even though the target-destination may have been renamed/removed or is temporarily ; unavailable, that doesn't invalidate the data integrity of the reparse-tag itself, especially when it may contain relative-path references ; ; Permission-Free access is used to open the link so as to resolve even System Links (as found in Vista+) - this can be misleading, as it does not indicate that using ; $sLink directly in the script outside of this function will likely fail as System Links have ACL's which deny access to everyone ; ; Related........: ; Link...........: ; Example........: ; =============================================================================================================================== #include <APIConstants.au3> #include <File.au3> #include <WinAPIEx.au3> Func _GetReparseTarget($sLink, $AbsPath = True) Local Enum $ID_UNKNOWN, $ID_SYMLINK, $ID_SYMLINK_RELATIVE, $ID_JUNCTION, $ID_MOUNT_POINT Local Enum $NOTFOUND = 1, $ACCESSDENIED, $NOTREPARSE, $NOTRESOLVED Local $tFindData = DllStructCreate($tagWIN32_FIND_DATA) Local $hFile = _WinAPI_FindFirstFile($sLink, DllStructGetPtr($tFindData)) ; Retrieve the attributes / verify existence / obtain the ReparseTag identifier If @error Then Return SetError($NOTFOUND, $ID_UNKNOWN, "") _WinAPI_FindClose($hFile) If BitAND(DllStructGetData($tFindData, "dwFileAttributes"), $FILE_ATTRIBUTE_REPARSE_POINT) Then Local Const $IO_REPARSE_TAG_SYMLINK = 0xA000000C Local Const $IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003 Local $Ret = "", $TypeID = $ID_UNKNOWN Local $Tag = _WinAPI_LoWord(DllStructGetData($tFindData, "dwReserved0")) Local $tREPARSE_GUID_DATA_BUFFER = _ "dword ReparseTag;" & _ "word ReparseDataLength;" & _ "word Reserved; " & _ "word SubstituteNameOffset;" & _ "word SubstituteNameLength;" & _ "word PrintNameOffset;" & _ "word PrintNameLength;" Select Case BitAND($Tag, $IO_REPARSE_TAG_SYMLINK) $TypeID = $ID_SYMLINK $tREPARSE_GUID_DATA_BUFFER &= "dword Flags;" ; Convert (default) struct MountPointReparseBuffer to struct SymbolicLinkReparseBuffer Case BitAND($Tag, $IO_REPARSE_TAG_MOUNT_POINT) $TypeID = $ID_JUNCTION Case Else Return SetError($NOTRESOLVED, $ID_UNKNOWN, "") EndSelect $hFile = _WinAPI_CreateFileEx($sLink, $OPEN_EXISTING, 0, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE, $FILE_SHARE_DELETE), _ ; dwDesiredAccess 0 (permission-free) BitOR($FILE_FLAG_BACKUP_SEMANTICS, $FILE_FLAG_OPEN_REPARSE_POINT)) If @error Then Return SetError($ACCESSDENIED, $TypeID, "") Local $RGDB = DllStructCreate($tREPARSE_GUID_DATA_BUFFER & "wchar PathBuffer[4096]") _WinAPI_DeviceIoControl($hFile, $FSCTL_GET_REPARSE_POINT, 0, 0, DllStructGetPtr($RGDB), DllStructGetSize($RGDB)) If Not @error Then Local Const $SYMLINK_FLAG_RELATIVE = 0x00000001 Local Const $SIZEOF_WCHAR = 2 Local $sBuffer = DllStructGetData($RGDB, "PathBuffer") ; Buffer "may" contain multiple strings "in any order" [MSDN]... Local $iOffset = DllStructGetData($RGDB, "SubstituteNameOffset") / $SIZEOF_WCHAR Local $iLength = DllStructGetData($RGDB, "SubstituteNameLength") / $SIZEOF_WCHAR $Ret = StringMid($sBuffer, 1 + $iOffset, $iLength) ; ...so always extract SubstituteName (despite its moniker) as the path-proper If StringLeft($Ret, 2) = "\?" Then $Ret = "\\" & StringMid($Ret, 3) ; DeviceIoControl loves substituting \??\ for more common \\?\, so we substitute it right back If $TypeID = $ID_SYMLINK And DllStructGetData($RGDB, "Flags") = $SYMLINK_FLAG_RELATIVE Then $TypeID = $ID_SYMLINK_RELATIVE If $Ret <> "" And $AbsPath Then $Ret = _PathFull($Ret, StringLeft($sLink, StringInStr($sLink, "\", 0, -1))) ; Convert to absolute path based from $sLink container EndIf Select ; Regulate possible mapped/unmapped UNC prefix genera or verify Mounted Volume ID by format Case StringRegExp($Ret, "(?i)\\Volume\{[a-f\d]{8}-([a-f\d]{4}-){3}[a-f\d]{12}\}\\$") ; "\Volume{GUID}\" $TypeID = $ID_MOUNT_POINT Case StringLeft($Ret, 8) = "\\?\UNC\" $Ret = StringReplace($Ret, "?\UNC\", "", 1) ; "\\?\UNC\server\share" -> "\\server\share" Case StringLeft($Ret, 4) = "\\?\" And StringMid($Ret, 6, 1) = ":" $Ret = StringTrimLeft($Ret, 4) ; "\\?\C:\FolderObject" -> "C:\FolderObject" EndSelect EndIf _WinAPI_CloseHandle($hFile) $RGDB = 0 If $Ret = "" Then Return SetError($NOTRESOLVED, $TypeID, "") Return SetExtended($TypeID, $Ret) EndIf Return SetError($NOTREPARSE, $ID_UNKNOWN, "") EndFunc Does what it says on the tin. Compatible with XP, Vista, Win7, etc. For a ridiculously long explanation on how it works (more or less for beginners with a sense of humour), and why GetFinalPathNameByHandle is not the way to go, and to see an extended example project it was created for, please see this. Simple example: #include "_GetReparseTarget.au3" $aList = _FileListToArray(@UserProfileDir) For $i = 1 To $aList[0] If BitAND(_WinAPI_GetFileAttributes(@UserProfileDir & "\" & $aList[$i]), $FILE_ATTRIBUTE_REPARSE_POINT) Then ConsoleWrite($aList[$i] & " >>>>> " & _GetReparseTarget(@UserProfileDir & "\" & $aList[$i]) & @LF) EndIf Next
    1 point
  4. More details are needed. Are those devices on lan? Or they don't, but they have access to internet?
    1 point
  5. #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 386, 95, 192, 124) $Label1 = GUICtrlCreateLabel("0.000001", 64, 24, 228, 33) GUISetState() $vDec = 0.000001 AdLibRegister("_add", 500) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _add() $vDec = $vDec + 1*10^-6 GUICtrlSetData($Label1, StringFormat("%.6f", $vDec)) EndFunc
    1 point
  6. water

    prtscn & send email

    Hotmail doesn't exist anymore Didn't think of that.
    1 point
  7. You need something like this: For $i = 0.000001 To 0.0001 Step 0.000001 ConsoleWrite(StringFormat("%1.6f", $i) & @LF) Next
    1 point
  8. BrewManNH

    prtscn & send email

    Maybe because Hotmail doesn't exist anymore? Have you tried it with smtp-mail.outlook.com as the SMTP server?
    1 point
  9. water

    prtscn & send email

    Jos gave you some goods tips in post >#28. Did you check the examples?
    1 point
  10. Jos

    prtscn & send email

    They are all merged into one and let's keep it like that. Jos
    1 point
  11. water

    prtscn & send email

    3aberxcs, you now have 3 threads about sending mails. Could you please explain why you need to start 3 threads?
    1 point
  12. Jos

    prtscn & send email

    Doubt the used standard SMTP port (25) is the correct one and for sure won't work on Gmail. Search Examples for _INetSmtpMailCom. Jos
    1 point
  13. What's wrong with _ArrayUnique()?
    1 point
  14. water

    prtscn & send email

    You need to give use more information. Post the error message you get, return codes etc.
    1 point
  15. water

    need help from masters...

    And check the return code before proceeding to the next step. Something like: RunWait(@ComSpec & " /c c:\adb.exe shell rm -r /sdcard/backup ", @ScriptDir, @SW_HIDE) If @error then Return @error ; Returns the error code to the function call
    1 point
  16. It's not OK.If you are really interested in something then put as much pressure on developers (Jon) as you can until you get response, otherwise you could just wait forever. Positive pressure is good for development, from my AutoIt experience it's almost essential. You have no reason to feel "sorry" for the developers, why in the world would you care for their effort distribution.
    1 point
×
×
  • Create New...