Sign in to follow this  
Followers 0
gosu

PixelDraw and DrawRectangle Functions

7 posts in this topic

#1 ·  Posted (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 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]

Share this post


Link to post
Share on other sites



@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. :)

Share this post


Link to post
Share on other sites

If $err Then Return 0
  Return 1
EndFunc
Larry, 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
EndIf

There is no documentation about If...Then statement like your code :):)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If $err Then Return 0
 Return 1
EndFunc

Larry, 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 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!

Share this post


Link to post
Share on other sites

Oh yess....I am an ;). why I don't realize this... :) :) :evil: :"> :idiot::D:idiot::D:(:idiot:

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 :blink:

Try it your self:

Example()
Exit
Func Example()
   If 1 = 1 Then Return 0
   Return MsgBox(4096,"","Will this print?")
EndFunc

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

$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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0