Skyrimfus

Overlay Rectangle with different edge colors

4 posts in this topic

#1 ·  Posted

I am using this udf:

#include <WinAPI.au3>

Func _Rect($start_x, $start_y, $iWidth, $iHeight, $iColor)
    Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 1,@DesktopWidth/2+$start_x)
    DllStructSetData($tRect, 2,@DesktopHeight/2+$start_y)
    DllStructSetData($tRect, 3,@DesktopWidth/2+ $iWidth+$start_x)
    DllStructSetData($tRect, 4,@DesktopHeight/2+ $iHeight+$start_y)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)

    _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush)

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

Can I create an rectangle with different colors at the edges that behaves similar to the function mentioned above?

Share this post


Link to post
Share on other sites



#2 ·  Posted

Uh sure? Not enough info to really give a better response. What are you doing this on? Are you going to create an actual GUI, or will you just be trying to draw a rectangle anywhere on the screen that's transparent? Are you trying to draw on some images?

Share this post


Link to post
Share on other sites

#4 ·  Posted

Not using the _WinApi_FrameRect. You could use _WinApi_DrawLine to draw each individual line

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

_Rect(0, 0, @DesktopWidth, @DesktopHeight, 0x0000FF, 0xFF0000, "", 0xFFFF00, 14)

Func _Rect($iX, $iY, $iWidth, $iHeight, $iColorTop, $iColorRight = Default, $iColorBottom = Default, $iColorLeft = Default, $iTopWidth = 1, $iRightWidth = Default, $iBottomWidth = Default, $iLeftWidth = Default)
    If ($iColorRight = Default or $iColorRight == "") Then $iColorRight = $iColorTop
    If ($iColorBottom = Default or $iColorBottom == "") Then $iColorBottom = $iColorTop
    If ($iColorLeft = Default or $iColorLeft == "") Then $iColorLeft = $iColorTop
    If ($iRightWidth = Default or $iRightWidth == "") Then $iRightWidth = $iTopWidth
    If ($iBottomWidth = Default or $iBottomWidth == "") Then $iBottomWidth = $iTopWidth
    If ($iLeftWidth = Default or $iLeftWidth == "") Then $iLeftWidth = $iTopWidth

    Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    ; Doing all the math of where to draw each line
    Local $aCoords[4][4] = [[$iX, $iY, $iX + $iWidth, $iY], _
                            [$iX + $iWidth, $iY, $iX + $iWidth, $iY + $iHeight], _
                            [$iX, $iY + $iHeight, $iX + $iWidth, $iY + $iHeight], _
                            [$iX, $iY, $iX, $iY + $iHeight]]
    ; Colors for each line
    Local $aColors[] = [$iColorTop, $iColorRight, $iColorBottom, $iColorLeft]
    ; Width of each line
    Local $aWidths[] = [$iTopWidth, $iRightWidth, $iBottomWidth, $iLeftWidth]

    For $i = 0 to UBound($aCoords) - 1
        ; Create a pen object, solid color, width will be the width provided, color is the color provided
        Local $hPen = _WinAPI_CreatePen($PS_SOLID, $aWidths[$i], $aColors[$i])
        ; Select the $hDC and use the $hPen for this line
        Local $oSelect = _WinAPI_SelectObject($hDC, $hPen)
        ; Draw the line
        _WinAPI_DrawLine($hDC, $aCoords[$i][0], $aCoords[$i][1], $aCoords[$i][2], $aCoords[$i][3])

        ; Free resources
        _WinAPI_DeleteObject($hPen)
        _WinAPI_SelectObject($hDC, $oSelect)
    Next

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

That should free up resources correctly. Draws in top, right, bottom, left order (Color and width provided is also in this order). Only need to provide the top color/width and the others will default to that if left default

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