gosu Posted November 10, 2004 Posted November 10, 2004 (edited) global $pixeldraw $pixeldraw = DLLCall("user32.dll","long","GetDC","hwnd",0) Func PixelDraw($xcoord, $ycoord, $color) DllCall("gdi32","long","SetPixel", "long", $pixeldraw[0], "long", $xcoord, "long", $ycoord, "long", $color) If @error = 1 Then Return 0 Else Return 1 EndIf EndFunc Func DrawRectangle($xstart, $ystart, $xend, $yend, $color) For $x = $xstart to $xend For $y = $ystart to $yend PixelDraw($x, $y, $color) Next Next EndFunc ; Example of how to draw a white rectangle DrawRectangle(600, 300, 750, 400, 0xFFFFFF) Thanks to ezzetabi for the API-Guide. I think this function may be pretty useful. (man, it took me long to see, that i have to call 2 dlls...) Althought, it´s really slow. Is there a way to speed it up? Edited November 10, 2004 by gosu [quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]
Josbe Posted November 10, 2004 Posted November 10, 2004 @gosu: I think that, it's good release the Device Context. (DC) Simply adding this line: DLLCall ("user32.dll", "int", "ReleaseDC", "hwnd", $hwnd, "int", $GDC[0]) BTW: You can see Larry's example. @Larry: Nice. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
stingjoel Posted November 11, 2004 Posted November 11, 2004 If $err Then Return 0 Return 1 EndFuncLarry, I see this code above in your scripts....can you explain the code....In my experience, the function will always have return value 1....or maybe this code is the same with this:If $err Then Return 0 Else Return 1 EndIfThere is no documentation about If...Then statement like your code
CyberSlug Posted November 11, 2004 Posted November 11, 2004 (edited) If $err Then Return 0 Return 1 EndFuncLarry, I see this code above in your scripts....can you explain the code....In my experience, the function will always have return value 1....<{POST_SNAPBACK}>If $err is true, then the "Return 0" is executed meaning that the function exits without any of the remaining lines being executed. "Return 1" is only executed when $err is false.Notice that is is two lines shorter than the corresponding If-then-else code. Programmers generally like to take shortcuts and type less Try it your self:Example() Exit Func Example() If 1 = 1 Then Return 0 Return MsgBox(4096,"","Will this print?") EndFunc Edited November 11, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
stingjoel Posted November 11, 2004 Posted November 11, 2004 Oh yess....I am an . why I don't realize this... :) :"> If $err is true, then the "Return 0" is executed meaning that the function exits without any of the remaining lines being executed. "Return 1" is only executed when $err is false.Notice that is is two lines shorter than the corresponding If-then-else code. Programmers generally like to take shortcuts and type less Try it your self:Example() Exit Func Example() If 1 = 1 Then Return 0 Return MsgBox(4096,"","Will this print?") EndFunc<{POST_SNAPBACK}>
gosu Posted November 11, 2004 Author Posted November 11, 2004 expandcollapse popup$a = DrawRectangle(600, 300, 750, 400, 0xFFFFFF) Func PixelDraw($xcoord, $ycoord, $color) $pixeldraw = DLLCall("user32.dll","int","GetDC","hwnd",0) If @error Then Return 0 DllCall("gdi32.dll","long","SetPixel", "long", $pixeldraw[0], _ "long", $xcoord, "long", $ycoord, "long", $color) $err = @error DLLCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$pixeldraw[0]) If $err Then Return 0 Return 1 EndFunc Func DrawRectangle($xstart, $ystart, $xend, $yend, $color) $rectdraw = DLLCall("user32.dll","int","GetDC","hwnd",0) If @error Then Return 0 $pen = DLLCall("gdi32.dll","int","CreatePen","int",0,"int",1,"int",$color) $err = @error If Not $err Then DLLCall("gdi32.dll","int","SelectObject","int",$rectdraw[0],"int",$pen[0]) If Not @error Then DLLCall("gdi32.dll","int","MoveToEx","int",$rectdraw[0],"int",_ $xstart,"int",$ystart,"int",0) DLLCall("gdi32.dll","int","LineTo","int",$rectdraw[0], _ "int",$xend,"int",$ystart) DLLCall("gdi32.dll","int","LineTo","int",$rectdraw[0], _ "int",$xend,"int",$yend) DLLCall("gdi32.dll","int","LineTo","int",$rectdraw[0], _ "int",$xstart,"int",$yend) DLLCall("gdi32.dll","int","LineTo","int",$rectdraw[0], _ "int",$xstart,"int",$ystart) DLLCall("gdi32.dll","int","DeleteObject","int",$pen[0]) EndIf EndIf DLLCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$rectdraw[0]) If $err Then Return 0 Return 1 EndFunc<{POST_SNAPBACK}>Ah, thanks. works real faster [quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]
amphoterous Posted October 28, 2005 Posted October 28, 2005 First off, I appologize for bring this thread back from the dead. But this bit of code is exactly what I need except for one thing: Is it possible to make the box it draws movable, resizable, and then return the coordinates of the box itself? If anyone has any ideas, please let me know! Thanks in advance.
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