sensalim Posted April 14, 2008 Posted April 14, 2008 Is it possible to draw a line (can able to change the color of the line) on the screen? Some kind of UDF maybe... like _drawline( start_x, start_y, end_x, end_y, color, color_mode, line_type) optionals: color_mode is 0 - COLORREF rgbcolor 1 - BGR hex 2 - RGB hex (default) line_type is 0 - dashes ie: -------- 1 - fill, thickness = 1 (default) 2 - fill, thickness = 2 3 - fill, thickness = 3 4 - dots ie: ........... 5 - dashes and dots ie: ...-...-... Of course this function is made up, I was just wondering if such thing possible...? Thanks.
ofLight Posted April 14, 2008 Posted April 14, 2008 One Meathod is to use a DLL call to draw directly onscreen, This is a rip from some code I use. $hdc = DllCall("user32.dll","int","GetDC","hwnd",0) For $i = 1 to $Path[0][0] $x = $Path[$i][0] $y = $Path[$i][1] DllCall("gdi32.dll","int","SetPixel","int",$hdc[0],"int",$x,"int",$y,"int",0xFF00FF) Next DllCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$hdc[0]) There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly
sensalim Posted April 14, 2008 Author Posted April 14, 2008 It remains on the screen... how do I make it disappear when I want to?
sensalim Posted April 14, 2008 Author Posted April 14, 2008 Having problem thinking how to create this array if I specify starting x,y and ending x,y coordinates... hm....
sensalim Posted April 14, 2008 Author Posted April 14, 2008 (edited) Ok how about this... expandcollapse popup;Includes #Include <Array.au3> ;Variables $debug = 1 Dim $Path[2][2] = [[2,2]] ;Make the Array ;MakeArray(0, 0, 500, 100, $Path) ;MakeArray(200, 100, 0, 300, $Path) ;MakeArray(0, 100, 500, 0, $Path) MakeArray(500, 100, 0, 0, $Path) ;Display Array (if $debug = 1) If $debug = 1 Then _ArrayDisplay($Path) EndIf ;Draw $hdc = DllCall("user32.dll","int","GetDC","hwnd",0) For $i = 1 to $Path[0][0]-1 $x = $Path[$i][0] $y = $Path[$i][1] DllCall("gdi32.dll","int","SetPixel","int",$hdc[0],"int",$x,"int",$y,"int",0xFF00FF) Next DllCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$hdc[0]) Exit ;$a must be 2 dimentional array Func MakeArray($startx, $starty, $endx, $endy, ByRef $a) $sz = 0 $xd = 0 $yd = 0 $tx = 0 $ty = 0 If $debug = 1 Then MsgBox(0, 'DEBUG', '$startx: ' & $startx & ' ... $starty: ' & $starty & @CRLF & '$endx: ' & $endx & ' ... $endy: ' & $endy) EndIf ;if reversed, swap both x and y If $endx < $startx and $endy < $starty Then ;swap x $tx = $endx $endx = $startx $startx = $tx ;swap y $ty = $endy $endy = $starty $starty = $ty EndIf ;x diff $xd = abs($endx - $startx) ;y diff $yd = abs($endy - $starty) ;size If $xd > $yd Then $sz = $xd Else $sz = $yd EndIf Dim $a[$sz][2] = [[$sz, 2]] If $debug = 1 Then MsgBox(0, 'DEBUG', '$sz is: ' & $sz & @CRLF & '$a[0][0] is: ' & $a[0][0]) EndIf For $i = 1 to $a[0][0]-1 ;x If $startx > $endx Then $a[$i][0] = Ceiling($startx - $i * ($xd / $sz)) Else $a[$i][0] = Ceiling($startx + $i * ($xd / $sz)) EndIf ;y If $starty > $endy Then $a[$i][1] = Ceiling($starty - $i * ($yd / $sz)) Else $a[$i][1] = Ceiling($starty + $i * ($yd / $sz)) EndIf Next EndFunc Edited April 14, 2008 by sensalim
sensalim Posted April 14, 2008 Author Posted April 14, 2008 Still have the problem of line drawn still stay on the screen... ideas?
covaks Posted April 15, 2008 Posted April 15, 2008 _WinAPI_Redrawwindow. eg: #include <WindowsConstants.au3> #include <WinAPI.au3> #Include <GDIPlus.au3> _GDIPlus_Startup () $hDC = _WinAPI_GetWindowDC(0) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $Color = 0xFF000000 $hPen = _GDIPlus_PenCreate($Color,2) For $y = 0 to 30 For $x = 0 to @DesktopWidth Step 5 _GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth/2, 0, $x, @DesktopHeight, $hPen) $Color += Hex(2) _GDIPlus_PenSetColor($hPen, $Color) Next Next _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_ALLCHILDREN) _WinAPI_ReleaseDC(0, $hDC) _GDIPlus_Shutdown()
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