Jump to content

Draw?


Nahuel
 Share

Recommended Posts

I swear I tried to make it work the way I want but I just can't figure it out, hehe.

I made this script (based on something I found googling):

#Include <Misc.au3>
HotKeySet("{F10}","_exit")
While 1
Sleep(25)
If _IsPressed(01) Then
    $LPos = MouseGetPos()
    $Color=0x94DF08
Do 
    $LPos1 = MouseGetPos()
    dibujar()
    Sleep(25)
Until NOT _IsPressed(01)

EndIf
WEnd
Func dibujar()
    $hand = DllCall("user32.dll","int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0 , "int",2, "int", $Color)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hand[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hand[0], "int", $LPos[0], "int", $LPos[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hand[0], "int", $LPos1[0], "int", $LPos1[1])
EndFunc
Func _exit()
    Exit
EndFunc

What I want to do is draw a line between the initial point (when you first click) and the current mouse position. It does work, but it won't delete the 'old' line (Is this even clear?) looking like this:

Posted Image

I tried using

DllCall("gdi32.dll", "hwnd", "DeleteObject", "hwnd", $Pen)

but it does nothing.

Anyone?

Edited by Nahuel
Link to comment
Share on other sites

Perhaps the lines you are drawing are just overwriting pixels in the window, and not creating vector-graphic objects that can be deleted? If so, "delete the line" would require knowing every pixel that was changed and what its old color was to restore. Else you could get the app that owns the window to refresh it, which would wipe out your changes.

I don't know, I'm just say'n...

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Something to help you get started.... use left mouse button to draw on screen....You need Auto3Lib.

#include <misc.au3>
#include <A3LWinAPI.au3>
Dim $Mpos_1 = "", $Mpos_1A = "", $Mpos_2 = "", $Mpos_2A = "", $line = ""
$LineColor = 0x00ff00; color BGR
$LineWidth = 5

HotKeySet( "{ESC}", "Get_Exit")

While 1
    ;Sleep(1)
    Global $hnd = _API_GetDesktopWindow()
    If _IsPressed(1) Then
        While _IsPressed(1)
            Local $firstPos = MouseGetPos()
            DrawBox($firstPos[0],$firstPos[1],$firstPos[0]+1,$firstPos[1]+1)
        WEnd
    EndIf
_API_RedrawWindow($hnd,Default,Default,$RDW_ERASENOW)
WEnd

Func Get_pos_one()
    GUICtrlDelete($line)
    $Ms_In = MouseGetPos()
    $Mpos_1 = $Ms_In[0]
    $Mpos_2 = $Ms_In[1]
    
EndFunc  ;==>Get_pos_one

Func Get_pos_two()
    GUICtrlDelete($line)
    $Ms_In2 = MouseGetPos()
    $Mpos_1A = $Ms_In2[0]
    $Mpos_2A = $Ms_In2[1]
    
EndFunc  ;==>Get_pos_two

Func DrawBox($firstPos_x, $firstPos_y, $secondPos_x, $secondPos_y)
    
    If $firstPos_x = "" Or $secondPos_x = "" Then
        Return
    EndIf

    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $firstPos_x, "int", $firstPos_y, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $secondPos_x, "int", $secondPos_y)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    
EndFunc  ;==>Get_drawing

Func Get_Exit()
    Exit
EndFunc  ;==>Get_Exit

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

Something to help you get started.... use left mouse button to draw on screen....You need Auto3Lib.

I don't think that addresses Nahuel's issue. His code does what he wants, but there is no easy way to go back and erase bit-mapped graphics elements. Yours don't erase, just as his didn't. The problem is that there is no "element" object to erase, it's just a bunch of pixels mixed in with the other pixels.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks you two!

But Toady, doesn't your script does the same thing mine does? (In fact, I thnk that's the one I found googling in the first place) Except that it draws dots instead of lines. The old ones stay there. I need the script to work on the whole screen. I can't make the whole screen refresh or block it.

-edit-

Oh, I see... I'll keep looking.. I hope someone knows :)

Edited by Nahuel
Link to comment
Share on other sites

Thanks you two!

But Toady, doesn't your script does the same thing mine does? (In fact, I thnk that's the one I found googling in the first place) Except that it draws dots instead of lines. The old ones stay there. I need the script to work on the whole screen. I can't make the whole screen refresh or block it.

-edit-

Oh, I see... I'll keep looking.. I hope someone knows :)

You solution is probably something like creating your own transparent full-screen window, drawing the line on that window (vice to other active windows), then you can erase the window each time you "repaint" the line. Include some logic to NOT erase/redraw when the mouse coordinate hasn't changed.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You solution is probably something like creating your own transparent full-screen window, drawing the line on that window (vice to other active windows), then you can erase the window each time you "repaint" the line. Include some logic to NOT erase/redraw when the mouse coordinate hasn't changed.

:)

Yeah, I thought of that before. But for some reason it makes my computer sssslllooooooooow.

Also, I made the window as big as my screen and set it as 'always on top', but somehow, I could still click on the icons and taskbar buttons...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...