Jump to content
Sign in to follow this  

_WinAPI_DrawLine disappears after creating multiples, (Fixed)

Recommended Posts

I'm trying to use the _WinAPI_DrawLine to black out sections of the screen prior to taking a screenshot "Redact Information"

It's mostly working, but for some reason if I create more than 4 or 5 black lines on the screen, they start randomly disappearing.

edit:  Turns out, it's a refresh thing, I was just applying to the desktop (0) over my Scite while it was running.  It appears that as the script run, Scite refreshes which breaks the overlay.  I switched my code to put those black lines over Notepad and they stayed until I clicked OK to close the script.


Below is a quick example to show what's going on (Updated with targeted handle).  It should show cascading black lines, but it's typically only showing the first 3 then a couple at the bottom.

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

$hwnd = ControlGetHandle("[CLASS:Notepad]", "", "[CLASS:Edit]")

For $i = 1 to 12

    $iX = 100 * $i
    $iY = 25 * $i
    $iX2 = $iX + 200
    $iY2 = $iY + 20
    $iH = 20

    _Rect($hwnd, $iX, $iY2 - ($iH / 2), $iX2, $iY2 - ($iH / 2), $iH, 0x000000)  ;Draws one black line, need it to be centered on the text

MsgBox(0, "Redacted", "There should be 12 black lines on the screen")

;function to draw a black line over text that should be redacted before taking screenshot
Func _Rect($iX, $iY, $iX2, $iY2, $iHeight, $iColor)
    If IsHWnd($hwnd) = 0 Then $hwnd = 0

    Local $hDC = _WinAPI_GetWindowDC($hwnd) ; DC of entire screen (desktop)

    ; Create a pen object, solid color, width will be the width provided, color is the color provided
    Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iHeight, $iColor)
    ; Select the $hDC and use the $hPen for this line
    Local $oSelect = _WinAPI_SelectObject($hDC, $hPen)
    ; Draw the line
    _WinAPI_DrawLine($hDC, $iX, $iY, $iX2, $iY2)


    ; Free resources
    _WinAPI_SelectObject($hDC, $oSelect)

    ; clear resources
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>_WinAPI_DrawRect






Edited by BigDaddyO

hmm... I guess I have to have a signature...

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...