Jump to content

WinActiveBorder()


Go to solution Solved by ioa747,

Recommended Posts

Posted

   image.png.17c4d3ac6303892b2501b80381c05baf.png     image.png.b058ae7ed68d8a40144fc66640da0d96.png    WinActiveBorder.zip  ( Source and icon. You compile your own. )

Spoiler
#include <GuiConstants.au3>
#include <guiconstantsex.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>
If WinExists(StringTrimRight(@ScriptName, 3) & 'GUI') Then Exit

_WinActiveBorder()
Func _WinActiveBorder($iColor = 0x009999, $iWidth = 2)
    If FileExists(StringTrimRight(@ScriptFullPath, 4) & ".ico") Then TraySetIcon(StringTrimRight(@ScriptFullPath, 4) & ".ico")
    If Int($iWidth) < 1 Then $iWidth = 1
    Local $aPos, $hWnd, $gX, $gY, $gW, $gH
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 3) & 'GUI', 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetBkColor($iColor)
    GUISetState()
    While 1
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
        If _WinAPI_GetIdleTime() > 10000 Then ContinueLoop
        $hWnd = WinGetHandle("[ACTIVE]")
        If @error Then ContinueLoop
        If $hWnd = $hGUI Then
            Send("!{TAB}")
            $hWnd = WinGetHandle("[ACTIVE]")
        EndIf
        $aPos = WinGetPos($hWnd)
        If @error Then ContinueLoop
        If __isTheSamePosAsBefore($aPos) Then ContinueLoop
        $gX = $aPos[0] + 7     ;X position ; left
        $gY = $aPos[1]         ;Y position ; top
        $gW = $aPos[2] - 14    ;Width      ; right
        $gH = $aPos[3] - 6     ;Height     ; buttom
        __GUICreateInvRect($aPos, $hGUI, $iWidth, $iWidth, $gW - ($iWidth * 2), $gH - ($iWidth * 2))
        WinMove($hGUI, "", $gX, $gY - $iWidth, $gW, $gH)
    WEnd
EndFunc   ;==>_WinActiveBorder

Func __GUICreateInvRect($aPos, $hWnd, $iX, $iY, $iW, $iH)
    Local $iLeftRect = 0
    Local $iTopRect = 0
    Local $hMask_1 = _WinAPI_CreateRectRgn($iLeftRect, $iTopRect, $aPos[2], $iY)
    Local $hMask_2 = _WinAPI_CreateRectRgn($iLeftRect, $iTopRect, $iX, $aPos[3])
    Local $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, $iTopRect, $aPos[2], $aPos[3])
    Local $hMask_4 = _WinAPI_CreateRectRgn($iLeftRect, $iY + $iH, $aPos[2], $aPos[3])
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)
    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)
    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)
EndFunc   ;==>_GUICreateInvRect

Func __isTheSamePosAsBefore($aPos, $iMaxOfTheSame = 3)
    Local Static $aWas[4], $iCount = 0
    $iCount += 1
    For $n = 0 To 3
        If $aWas[$n] <> $aPos[$n] Then
            $aWas = $aPos
            $iCount = 0
            Return 0
        EndIf
    Next
    If $iCount < $iMaxOfTheSame Then Return 0
    $aWas = $aPos
    Return 1
EndFunc   ;==>isTheSameAsBefore

I draws a border on the active window. A rehash of @careca's code, so don't think too highly of me :lol:
And is not perfect but, it tends to do what it claims. My happy new year code :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Instead of drawing the 4 sides individually, you could use this function :

Func Rect($hWnd, $iX, $iY, $iWidth, $iHeight, $iSize = 4)
  Local $hMain = _WinAPI_CreateRectRgn($iX, $iY, $iX + $iWidth, $iY + $iHeight)
  Local $hMask = _WinAPI_CreateRectRgn($iX + $iSize, $iY + $iSize, $iX + $iWidth - $iSize, $iY + $iHeight - $iSize)
  _WinAPI_CombineRgn($hMain, $hMain, $hMask, $RGN_DIFF)
  _WinAPI_DeleteObject($hMask)
  _WinAPI_SetWindowRgn($hWnd, $hMain)
EndFunc   ;==>Rect

 

Posted (edited)

image.png.1dd0b69e988c1a85810c387bbd8fb3f4.png

#include <GuiConstants.au3>
#include <guiconstantsex.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>
If WinExists(StringTrimRight(@ScriptName, 3) & 'GUI') Then Exit

;~ #RequireAdmin ; for elevated windows

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    GUIDelete()
    Exit
EndFunc   ;==>Terminate, like, emergency exit while testing  =)

_WinActiveBorder()
Func _WinActiveBorder($iColor = 0xFF9999, $iWidth = 3)
    $iWidth += 5
    If FileGetSize("WinActiveBorder.ico") Then TraySetIcon("WinActiveBorder.ico")
    If Int($iWidth) < 1 Then $iWidth = 1
    Local $aPos, $hWnd, $gX, $gY, $gW, $gH
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 3) & 'GUI', 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT))
    GUISetBkColor($iColor)
    GUISetState()
    While 1
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
        If _WinAPI_GetIdleTime() > 10000 Then ContinueLoop
        $hWnd = WinGetHandle("[ACTIVE]")
        If @error Then ContinueLoop
        If $hWnd = $hGUI Then
            Send("!{TAB}")
            $hWnd = WinGetHandle("[ACTIVE]")
        EndIf
        $aPos = WinGetPos($hWnd)
        If @error Then ContinueLoop
        If __isTheSamePosAsBefore($aPos) Then ContinueLoop
        $gX = $aPos[0] + 5      ;X position ; left
        $gY = $aPos[1]        ;Y position ; top
        $gW = $aPos[2] - 10    ;Width      ; right
        $gH = $aPos[3] - 5     ;Height     ; buttom
        __Rect($hGUI, 0, 0, $gW + ($iWidth * 2) - 10, $gH + ($iWidth * 2) - 10, $iWidth)
        _WinAPI_SetWindowPos($hGUI, $hWnd, $gX - $iWidth + 5, $gY - $iWidth + 5, $gW + ($iWidth * 2) - 10, $gH + ($iWidth * 2) - 10, $SWP_SHOWWINDOW)
    WEnd
EndFunc   ;==>_WinActiveBorder

Func __Rect($hWnd, $iX, $iY, $iWidth, $iHeight, $iSize = 40)
    Local $hMain = _WinAPI_CreateRectRgn($iX, $iY, $iX + $iWidth, $iY + $iHeight)
    Local $hMask = _WinAPI_CreateRectRgn($iX + $iSize, $iY + $iSize, $iX + $iWidth - $iSize, $iY + $iHeight - $iSize)
    _WinAPI_CombineRgn($hMain, $hMain, $hMask, $RGN_DIFF)
    _WinAPI_DeleteObject($hMask)
    _WinAPI_SetWindowRgn($hWnd, $hMain)
EndFunc   ;==>__Rect

Func __isTheSamePosAsBefore($aPos, $iMaxOfTheSame = 3)
    Local Static $aWas[4], $iCount = 0
    $iCount += 1
    For $n = 0 To 3
        If $aWas[$n] <> $aPos[$n] Then
            $aWas = $aPos
            $iCount = 0
            Return 0
        EndIf
    Next
    If $iCount < $iMaxOfTheSame Then Return 0
    $aWas = $aPos
    Return 1
EndFunc   ;==>__isTheSamePosAsBefore

.. thanks @Nine :)

 

Back story: I have "Win 11 - GUI set border color" for Win11. This is for Win10 and me, with an all dark theme and the borders, without a visible shadow running on a remote desktop, put all this together as a test but thought that may come in handy for some of you too.

Edited by argumentum
back story

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted (edited)

idea  for dialog windows, like this in the scite with shift + f8 (parameters) or like  ctrl + f (find)

Spoiler
#include <GuiConstants.au3>
#include <guiconstantsex.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>
If WinExists(StringTrimRight(@ScriptName, 3) & 'GUI') Then Exit

;~ #RequireAdmin ; for elevated windows

Opt("TrayAutoPause", 0) ; *** <--

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    GUIDelete()
    Exit
EndFunc   ;==>Terminate, like, emergency exit while testing  =)

_WinActiveBorder()
Func _WinActiveBorder($iColor = 0xFF9999, $iWidth = 3)
    $iWidth += 5
    If FileGetSize("WinActiveBorder.ico") Then TraySetIcon("WinActiveBorder.ico")
    If Int($iWidth) < 1 Then $iWidth = 1
    Local $aPos, $hWnd, $gX, $gY, $gW, $gH
    Local $aClsz, $iFrameDiff, $iFrame = 7 ; *** <--
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 3) & 'GUI', 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT))
    GUISetBkColor($iColor)
    GUISetState()
    While 1
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
        If _WinAPI_GetIdleTime() > 10000 Then ContinueLoop
        $hWnd = WinGetHandle("[ACTIVE]")
        If @error Then ContinueLoop
        If $hWnd = $hGUI Then
            Send("!{TAB}")
            $hWnd = WinGetHandle("[ACTIVE]")
        EndIf
        $aPos = WinGetPos($hWnd)
        If @error Then ContinueLoop
        $aClsz = WinGetClientSize($hWnd)                    ; *** <--
        $iFrameDiff = ($aPos[2] -  $aClsz[0]) / 2
        $iFrame = ($iFrameDiff > 7 ? 7 : $iFrameDiff)
        If __isTheSamePosAsBefore($aPos) Then ContinueLoop
        $gX = $aPos[0] + $iFrame      ;X position ; left
        $gY = $aPos[1]                ;Y position ; top
        $gW = $aPos[2] - 2 * $iFrame  ;Width      ; right
        $gH = $aPos[3] - $iFrame      ;Height     ; buttom  ; *** <--
        __Rect($hGUI, 0, 0, $gW + ($iWidth * 2) - 10, $gH + ($iWidth * 2) - 10, $iWidth)
        _WinAPI_SetWindowPos($hGUI, $hWnd, $gX - $iWidth + 5, $gY - $iWidth + 5, $gW + ($iWidth * 2) - 10, $gH + ($iWidth * 2) - 10, $SWP_SHOWWINDOW)
    WEnd
EndFunc   ;==>_WinActiveBorder

Func __Rect($hWnd, $iX, $iY, $iWidth, $iHeight, $iSize = 40)
    Local $hMain = _WinAPI_CreateRectRgn($iX, $iY, $iX + $iWidth, $iY + $iHeight)
    Local $hMask = _WinAPI_CreateRectRgn($iX + $iSize, $iY + $iSize, $iX + $iWidth - $iSize, $iY + $iHeight - $iSize)
    _WinAPI_CombineRgn($hMain, $hMain, $hMask, $RGN_DIFF)
    _WinAPI_DeleteObject($hMask)
    _WinAPI_SetWindowRgn($hWnd, $hMain)
EndFunc   ;==>__Rect

Func __isTheSamePosAsBefore($aPos, $iMaxOfTheSame = 3)
    Local Static $aWas[4], $iCount = 0
    $iCount += 1
    For $n = 0 To 3
        If $aWas[$n] <> $aPos[$n] Then
            $aWas = $aPos
            $iCount = 0
            Return 0
        EndIf
    Next
    If $iCount < $iMaxOfTheSame Then Return 0
    $aWas = $aPos
    Return 1
EndFunc   ;==>__isTheSamePosAsBefore

 

... and  🎇Happy New Year 🎇

Edited by ioa747

I know that I know nothing

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
  • Recently Browsing   0 members

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