Sign in to follow this  
Followers 0
vivec45

Drawing issue

1 post in this topic

#1 ·  Posted (edited)

Edit: NVM I figured it out, was closing handle or w/e.

HotKeySet("{PgUp}", "SetCoords1")
HotKeySet("{PgDn}", "SetCoords2")
HotKeySet("{DEL}", "Draw")
HotKeySet("{HOME}", "Redraw")

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>

Global $X1 = 0
Global $Y1 = 0

Global $X2 = 0
Global $Y2 = 0

$Drawn = False

_GDIPlus_Startup ()

$hDC = _WinAPI_GetWindowDC(0)

$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
$Color = 0xFF000000
$hPen = _GDIPlus_PenCreate($Color,2)

Func Reset()
    Redraw()
$X1 = 0
$Y1 = 0
$X2 = 0
$Y2 = 0
EndFunc

Func SetCoords1()
    $pos = MouseGetPos()
    $X1 = $pos[0]
    $Y1 = $pos[1]
EndFunc

Func SetCoords2()
    $pos = MouseGetPos()
    $X2 = $pos[0]
    $Y2 = $pos[1]
EndFunc

Func Draw()
    _GDIPlus_GraphicsDrawLine($hGraphic, $X1, $Y1, $X2, $Y2, $hPen)
    ;$Color += Hex(2)
    ;_GDIPlus_PenSetColor($hPen, $Color)
    $Drawn = True
EndFunc

Func Redraw()
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_ALLCHILDREN)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc

Func _IsPressed($hexKey) 
    Local $aR, $bO 
    $hexKey = '0x' & $hexKey 
    $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) 
    If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then 
            $bO = 1 
        Else 
        $bO = 0
    EndIf
    Return $bO
EndFunc

While 1
    ;If _IsPressed(0x2E) Then
        ;Sleep(0)
        ;Else
        ;If $Drawn Then
        ;Redraw()
        ;ToolTip("Redraw")
        ;$Drawn = False
            ;Else
            ;Sleep(0)
    ;EndIf
    ;EndIf
    Sleep(0)
WEnd

Hey everyone,

I'm having an issue with this code, it draws the line fine, but then after I call Reset to erase the line, it won't work any more until I restart it, just won't draw lines anymore. Does anyone know why? The code that draws the line isn't mine and I have no idea what I'm doing wrong.

Thanks,

Vivec45

Edited by vivec45

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