Jump to content

_WinAPI_DrawLine()


 Share

Recommended Posts

Hi,

I seem to be unable to erase a line drawn with WinAPI_DrawLine(). I am trying to make a line that starts at the mouse's position when the button was pressed, and end at the mouse's current position. The problem is that _WinAPI_RedrawWindow() doesn't erase the line. My code is as follows.

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>


While 1
If _IsPressed(11) Then
        $hDC = _WinAPI_GetWindowDC(0) 
        $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0xFF)
        $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
        
        $LineStart = MouseGetPos()
        
        Do
            $LineEnd = MouseGetPos()
            _WinAPI_DrawLine($hDC, $LineStart[0], $LineStart[1], $LineEnd[0], $LineEnd[1]) 
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0)
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_ERASE)
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
            
            _WinAPI_RedrawWindow($hDC, 0, 0)
            _WinAPI_RedrawWindow($hDC, 0, 0, $RDW_ERASE)
            _WinAPI_RedrawWindow($hDC, 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
        Until Not _IsPressed(11)
    
        ; refresh desktop (clear cross)
        _WinAPI_RedrawWindow($hDC, 0, 0);, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
        ; clear resources
        _WinAPI_SelectObject($hDC, $obj_orig)
        _WinAPI_DeleteObject($hPen)
        _WinAPI_ReleaseDC(0, $hDC)

    EndIf
    
WEnd

Any help is appreciated,

Zach

Link to comment
Share on other sites

Read this function description, it's exposed from gdi32.dll if you know how to use DllCall(). You can use R2_XORPEN to draw using the inverse of the pen color currently selected into the device content. Another easy solution would be to use _GDIPlus_GraphicsClear() to clear a graphic object (hDC in short ~) to the specified color.

Link to comment
Share on other sites

Read this function description, it's exposed from gdi32.dll if you know how to use DllCall(). You can use R2_XORPEN to draw using the inverse of the pen color currently selected into the device content. Another easy solution would be to use _GDIPlus_GraphicsClear() to clear a graphic object (hDC in short ~) to the specified color.

I'd like to avoid using the first method if possible, it looks really complicated. Unfortunately, _GDIPlus_GraphicsClear() does seemingly nothing in my program. I don't understand why _WinAPI_RedrawWindow() works in the example script, but not in mine. If you can come up with anything else, I'm all ears.

Thanks,

Zach

Link to comment
Share on other sites

Because redrawing a window requires a window handle, not a device context. :(

Edit:By the way, very cool graphic stuff. >_<

Okay, I did get _WinAPI_RedrawWindow() to work, but not quite the way I wanted it to. The thing is that a line is drawn with _WinAPI_DrawLine draws a line, when the key is released _WinAPI_RedrawWindow() makes the line invisible. The problem, however, is that when another line is drawn, the old line becomes visible as well.

Any help is appreciated,

Zach

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...