Jump to content

Creates a rectangle frame


Recommended Posts

 

; https://www.autoitscript.com/forum/topic/211986-creates-a-rectangle-frame/
;----------------------------------------------------------------------------------------
; Title...........: _GuiFrame.au3
; Description.....: Creates a rectangle frame
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

;Example:
Global $aCoord, $hPoint, $hFrame = _GuiFrame("", 100, 100, 200, 200, 5, 0xFFFFFF, 255)

;**********************************
Do
    $aCoord = PixelSearch(100, 100, 200, 200, 0xFFFFFF, 0, 1, 0) ;0xFFFFFF White
    If Not @error Then
        ConsoleWrite("found White at X,Y: " & $aCoord[0] & "," & $aCoord[1] & @CRLF)
        $hPoint = _GuiFrame("", $aCoord[0], $aCoord[1], $aCoord[0] + 1, $aCoord[1] + 1, 3, 0xFF0000)
        Sleep(4000)
        GUIDelete($hPoint)
    EndIf
    Sleep(10)
Until GUIGetMsg() = -3  ; GUI_EVENT_CLOSE
;**********************************

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _GuiFrame
; Description....: Creates a rectangle frame
; Syntax.........: _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom [, $iThickness = 2 [, $iColor = 0xFF0000 [, $iTransparency = 150 [, $hWndParent = 0]]]])
; Parameters.....: $sTitle        - The title of frame.
;                  $iLeft         - The left coordinate of frame.
;                  $iTop          - The top coordinate of frame.
;                  $iRight        - The right coordinate of frame.
;                  $iBottom       - The bottom coordinate of frame.
;                  $iThickness    - [optional] The thickness of frame (default = 1).
;                  $iColor        - [optional] The color of frame (default = 0xFF0000).
;                  $iTransparency - [optional] The transparency of frame, in the range 1 - 255 (default = 150).
;                  $hWndParent    - [optional] The parent window handle (default = 0).
; Return values..: The handle of the created frame.
; Author ........: ioa747
; Notes .........: Note that coordinate, are the internal frame dimensions.
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom, $iThickness = 1, $iColor = 0xFF0000, $iTransparency = 150, $hWndParent = 0)

    If $iThickness < 1 Or $iThickness = Default Then $iThickness = 1
    If $iColor = -1 Or $iColor = Default Then $iColor = 0xFF0000
    If $iTransparency < 1 Or $iTransparency = Default Or $iTransparency > 255 Then $iTransparency = 150

    Local $iWidth = $iRight - $iLeft + (2 * $iThickness) + 1
    Local $iHeight = $iBottom - $iTop + (2 * $iThickness) + 1
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft - $iThickness, $iTop - $iThickness, _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE), $hWndParent)

    GUISetBkColor($iColor, $hGUI)
    WinSetTrans($hGUI, "", $iTransparency)   ;255 = Solid, 0 = Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

    Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn
    $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
    $hInner_rgn = _WinAPI_CreateRectRgn($iThickness, $iThickness, $iWidth - $iThickness, $iHeight - $iThickness)
    $hCombined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($hInner_rgn)
    _WinAPI_SetWindowRgn($hGUI, $hCombined_rgn)
    Return $hGUI
EndFunc   ;==>_GuiFrame
;--------------------------------------------------------------------------------------------------------------------------------

 

Another example

#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISys.au3>

_Example1()

Func _Example1()

    Local $iGuiFrame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
    Local $iThickness = 10

    Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi! Move this window around'')"')

    Local $hWnd = WinWaitActive('Hello World!', '', 3)
    Local $aPos = WinGetPos($hWnd)

    Local $iLeft = $aPos[0] + $iGuiFrame
    Local $iTop = $aPos[1]
    Local $iRight = $aPos[0] + $aPos[2] - $iGuiFrame
    Local $iBottom = $aPos[1] + $aPos[3] - $iGuiFrame

    Local $hFrame = _GuiFrame("", $iLeft, $iTop, $iRight, $iBottom, $iThickness, 0xFF0000, 150, $hWnd)
    ConsoleWrite("$hFrame=" & $hFrame & @CRLF)

    Local $sStrPos

    While WinExists($hWnd)
        $aPos = WinGetPos($hWnd)
        If $sStrPos <> $aPos[0] & ";" & $aPos[1] Then
            WinMove($hFrame, '', $aPos[0] - $iThickness + $iGuiFrame, $aPos[1] - $iThickness)
            $sStrPos = $aPos[0] & ";" & $aPos[1]
        EndIf
        Sleep(10)
    WEnd
EndFunc   ;==>_Example1

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _GuiFrame
; Description....: Creates a rectangle frame
; Syntax.........: _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom [, $iThickness = 2 [, $iColor = 0xFF0000 [, $iTransparency = 150 [, $hWndParent = 0]]]])
; Parameters.....: $sTitle        - The title of frame.
;                  $iLeft         - The left coordinate of frame.
;                  $iTop          - The top coordinate of frame.
;                  $iRight        - The right coordinate of frame.
;                  $iBottom       - The bottom coordinate of frame.
;                  $iThickness    - [optional] The thickness of frame (default = 1).
;                  $iColor        - [optional] The color of frame (default = 0xFF0000).
;                  $iTransparency - [optional] The transparency of frame, in the range 1 - 255 (default = 150).
;                  $hWndParent    - [optional] The parent window handle (default = 0).
; Return values..: The handle of the created frame.
; Author ........: ioa747
; Notes .........: Note that coordinate, are the internal frame dimensions.
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom, $iThickness = 1, $iColor = 0xFF0000, $iTransparency = 150, $hWndParent = 0)

    If $iThickness < 1 Or $iThickness = Default Then $iThickness = 1
    If $iColor = -1 Or $iColor = Default Then $iColor = 0xFF0000
    If $iTransparency < 1 Or $iTransparency = Default Or $iTransparency > 255 Then $iTransparency = 150

    Local $iWidth = $iRight - $iLeft + (2 * $iThickness) + 1
    Local $iHeight = $iBottom - $iTop + (2 * $iThickness) + 1
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft - $iThickness, $iTop - $iThickness, _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE), $hWndParent)

    GUISetBkColor($iColor, $hGUI)
    WinSetTrans($hGUI, "", $iTransparency) ;255 = Solid, 0 = Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

    Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn
    $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
    $hInner_rgn = _WinAPI_CreateRectRgn($iThickness, $iThickness, $iWidth - $iThickness, $iHeight - $iThickness)
    $hCombined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($hInner_rgn)
    _WinAPI_SetWindowRgn($hGUI, $hCombined_rgn)
    Return $hGUI
EndFunc   ;==>_GuiFrame
;--------------------------------------------------------------------------------------------------------------------------------

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

and one with Hover effect

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

; get height of window title and width of window frame - may be different when XP theme is ON/OFF
Global $iGuiMetricsTitle = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $iGuMetricsiFrame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
Global $bInfo = False ; *** <-- True = more ConsoleWrite info
Global $g_idMemo, $MyGui, $a_idBtn[7]

Example()

;--------------------------------------------------------------------------------------------------------------------------------
Func Example()

    $MyGui = GUICreate("Button Get/Set ImageList (v" & @AutoItVersion & ")", 510, 400)
    $g_idMemo = GUICtrlCreateEdit("", 119, 10, 376, 374, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    $a_idBtn[0] = 6
    Local $y = 20, $iWidth = 90, $iHeight = 50
    For $x = 1 To $a_idBtn[0]
        $a_idBtn[$x] = GUICtrlCreateButton("Button" & $x, 10, $y, $iWidth, $iHeight)
        $y += 60
    Next

    Local $iMsg

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $a_idBtn[1] To $a_idBtn[$a_idBtn[0]]
                MemoWrite("cklick " & GUICtrlRead($a_idBtn[$iMsg - $a_idBtn[1] + 1]))

        EndSwitch

        _Hover()

        Sleep(10)
    WEnd

    Exit
EndFunc   ;==>Example
;--------------------------------------------------------------------------------------------------------------------------------
Func _Hover($iThickness = 5, $FrameColor = 0x00FFFF, $iTransparency = 100)
    Local Static $iActive, $hFrame

    If Not WinActive($MyGui) Then Return SetError(1, 0, False)

    Local $ActiveCtrl
    Local $aCtrl = GUIGetCursorInfo($MyGui)
    $ActiveCtrl = IsArray($aCtrl) ? $aCtrl[4] : 0

    If $iActive <> $ActiveCtrl Then
        $iActive = $ActiveCtrl
        DW("> $iActive=" & $iActive & @CRLF)
        Local $Msg

        ;if frame exist => obsolete => FrameDelete
        If $hFrame Then
            $Msg = GUIDelete($hFrame)
            DW("!! ObsoleteFrameDelete(" & $hFrame & ")=" & $Msg & @CRLF)
            $hFrame = Null
        EndIf

        ;Rule1 $ActiveCtrl = 0 => Return
        If $ActiveCtrl = 0 Then
            DW("<< $ActiveCtrl = 0" & @CRLF & @CRLF)
            Return SetError(2, 0, False)
        EndIf

        ;Rule2 if not $a_idBtn => Return
        If $ActiveCtrl < $a_idBtn[1] Or $ActiveCtrl > $a_idBtn[$a_idBtn[0]] Then
            DW("<< Only from:" & $a_idBtn[1] & " to:" & $a_idBtn[$a_idBtn[0]] & @CRLF & @CRLF)
            Return SetError(3, 0, False)
        EndIf

        ;recheck obsoleteFrameDelete
        If $hFrame Then
            $Msg = GUIDelete($hFrame)
            DW("!!!! recheck ObsoleteFrameDelete(" & $hFrame & ")=" & $Msg & @CRLF)
        EndIf

        Local $aPos = WinGetPos($MyGui)
        Local $sName = GUICtrlRead($ActiveCtrl)
        Local $aCtrlPos = ControlGetPos($MyGui, '', $ActiveCtrl)

        Local $iLeft = $iGuMetricsiFrame + $aPos[0] + $aCtrlPos[0]
        Local $iTop = $iGuMetricsiFrame + $iGuiMetricsTitle + $aPos[1] + $aCtrlPos[1]
        Local $iRight = $aCtrlPos[2]
        Local $iBottom = $aCtrlPos[3]

        DW("- Ctrl:" & $ActiveCtrl & " | Name:" & $sName & " | X,Y,W,H: " & $aCtrlPos[0] & ", " & $aCtrlPos[1] & ", " & $aCtrlPos[2] & ", " & $aCtrlPos[3] & _
                " | WinPos: " & $aPos[0] & ", " & $aPos[1] & ", " & $aPos[2] & ", " & $aPos[3] & @CRLF)

        $hFrame = _GuiFrame("frame_" & $sName, $iLeft, $iTop, $iRight, $iBottom, $iThickness, $FrameColor, $iTransparency, $MyGui, 1)         ;normal
        DW("+ NewFrame: " & $hFrame & " : " & $iLeft & ", " & $iTop & ", " & $iRight & ", " & $iBottom & @CRLF & @CRLF)

    EndIf

    Sleep(10)

EndFunc   ;==>_Hover
;--------------------------------------------------------------------------------------------------------------------------------
Func MemoWrite($sMessage) ; Write a line to the memo control
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
;--------------------------------------------------------------------------------------------------------------------------------
Func DW($sText)
    If Not $bInfo Then Return
    ConsoleWrite($sText)
EndFunc   ;==>DW

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _GuiFrame
; Description....: Creates a rectangle frame
; Syntax.........: _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom [, $iThickness = 2 [, $iColor = 0xFF0000 [, $iTransparency = 150 [, $hWndParent = 0 [, $iFlag = 0 ]]]]])
; Parameters.....: $sTitle        - The title of frame.
;                  $iLeft         - The left coordinate of frame.
;                  $iTop          - The top coordinate of frame.
;                  $iRight        - The right coordinate of frame.
;                  $iBottom       - The bottom coordinate of frame.
;                  $iThickness    - [optional] The thickness of frame (default = 1).
;                  $iColor        - [optional] The color of frame (default = 0xFF0000).
;                  $iTransparency - [optional] The transparency of frame, in the range 1 - 255 (default = 150).
;                  $hWndParent    - [optional] The parent window handle (default = 0).
;                  $iFlag         - [optional] $iFlag=0 $iRight=$iRight and $iBottom=$iBottom (default = 0).
;                                              $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
; Return values..: The handle of the created frame.
; Author ........: ioa747
; Notes .........: Note that coordinate, are the internal frame dimensions.
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom, $iThickness = 1, $iColor = 0xFF0000, $iTransparency = 150, $hWndParent = 0, $iFlag = 0)
    If $iThickness < 1 Or $iThickness = Default Then $iThickness = 1
    If $iColor = -1 Or $iColor = Default Then $iColor = 0xFF0000
    If $iTransparency < 1 Or $iTransparency = Default Or $iTransparency > 255 Then $iTransparency = 150
    Local $iWidth, $iHeight

    If $iFlag = 1 Then ; $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
        $iWidth = $iRight + (2 * $iThickness)
        $iHeight = $iBottom + (2 * $iThickness)
    Else
        $iFlag = 0
        $iWidth = $iRight - $iLeft + (2 * $iThickness) + 1
        $iHeight = $iBottom - $iTop + (2 * $iThickness) + 1
    EndIf
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft - $iThickness, $iTop - $iThickness, _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE), $hWndParent)

    GUISetBkColor($iColor, $hGUI)
    WinSetTrans($hGUI, "", $iTransparency) ;255 = Solid, 0 = Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

    Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn
    $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
    $hInner_rgn = _WinAPI_CreateRectRgn($iThickness, $iThickness, $iWidth - $iThickness, $iHeight - $iThickness)
    $hCombined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($hInner_rgn)
    _WinAPI_SetWindowRgn($hGUI, $hCombined_rgn)
    Return $hGUI
EndFunc   ;==>_GuiFrame
;--------------------------------------------------------------------------------------------------------------------------------

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

I know that I know nothing

Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

I added a new parameter:
$MDICHILD      - [optional] Create as child, that will be moved with parent  (default = False).

 

#include <WindowsConstants.au3>
#include <WinAPIDlg.au3>
#include <WinAPIGdi.au3>

Local $aInput[11], $aFrame[11]
$aInput[0] = 10
$aFrame[0] = 10

Local $Form1 = GUICreate("Form1", 286, 165, 853, 226)
GUISetFont(11)
; Create Input
Local $iX = 10, $iY = 10
For $i = 1 To $aInput[0]
    $aInput[$i] = GUICtrlCreateInput(Random(-100, 100, 1), $iX, $iY, 121, 21)
    $iY += 30
    If $i = 5 Then
        $iX = 150
        $iY = 10
    EndIf
Next
GUISetState(@SW_SHOW)

; Create Frame
$iX = 10
$iY = 10
Local $Color, $iVal
For $i = 1 To $aInput[0]
    $iVal = GUICtrlRead($aInput[$i])
    If $iVal < 0 Then
        $Color = 0xFF0000
    ElseIf $iVal > 0 Then
        $Color = 0x00FF21
    Else
        $Color = 0x0026FF
    EndIf

    $aFrame[$i] = _GuiFrame("", $iX, $iY, 121, 21, 2, $Color, 150, $Form1, True, 1)
    $iY += 30
    If $i = 5 Then
        $iX = 150
        $iY = 10
    EndIf
Next

;**********************************
While 1
    Switch GUIGetMsg()
        Case -3 ;$GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    Sleep(10)
WEnd
;**********************************


; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _GuiFrame
; Description....: Creates a rectangle frame
; Syntax.........: _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom [, $iThickness = 2 [, $iColor = 0xFF0000 [, $iTransparency = 150 [, $hWndParent = 0 [, $MDICHILD = False [, $iFlag = 0 ]]]]]])
; Parameters.....: $sTitle        - The title of frame.
;                  $iLeft         - The left coordinate of frame.
;                  $iTop          - The top coordinate of frame.
;                  $iRight        - The right coordinate of frame.
;                  $iBottom       - The bottom coordinate of frame.
;                  $iThickness    - [optional] The thickness of frame (default = 1).
;                  $iColor        - [optional] The color of frame (default = 0xFF0000).
;                  $iTransparency - [optional] The transparency of frame, in the range 1 - 255 (default = 150).
;                  $MDICHILD      - [optional] Create as child, that will be moved with parent  (default = False).
;                  $hWndParent    - [optional] The parent window handle (default = 0).
;                  $iFlag         - [optional] $iFlag=0 $iRight=$iRight and $iBottom=$iBottom (default = 0).
;                                              $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
; Return values..: The handle of the created frame.
; Author ........: ioa747
; Notes .........: Note that coordinate, are the internal frame dimensions.
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom, $iThickness = 1, $iColor = 0xFF0000, $iTransparency = 150, $hWndParent = 0, $MDICHILD = False, $iFlag = 0)
    If $iThickness < 1 Or $iThickness = Default Then $iThickness = 1
    If $iColor = -1 Or $iColor = Default Then $iColor = 0xFF0000
    If $iTransparency < 1 Or $iTransparency = Default Or $iTransparency > 255 Then $iTransparency = 150
    Local $iWidth, $iHeight

    If $iFlag = 1 Then ; $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
        $iWidth = $iRight + (2 * $iThickness)
        $iHeight = $iBottom + (2 * $iThickness)
    Else
        $iFlag = 0
        $iWidth = $iRight - $iLeft + (2 * $iThickness) + 1
        $iHeight = $iBottom - $iTop + (2 * $iThickness) + 1
    EndIf
    Local $ExStyle
    If $hWndParent <> 0 And $MDICHILD = True Then
        $ExStyle = BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE, $WS_EX_MDICHILD)
    Else
        $ExStyle = BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE)
    EndIf
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft - $iThickness, $iTop - $iThickness, _
            $WS_POPUP, $ExStyle, $hWndParent)

    GUISetBkColor($iColor, $hGUI)
    WinSetTrans($hGUI, "", $iTransparency) ;255 = Solid, 0 = Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

    Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn
    $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
    $hInner_rgn = _WinAPI_CreateRectRgn($iThickness, $iThickness, $iWidth - $iThickness, $iHeight - $iThickness)
    $hCombined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($hInner_rgn)
    _WinAPI_SetWindowRgn($hGUI, $hCombined_rgn)
    Return $hGUI
EndFunc   ;==>_GuiFrame
;--------------------------------------------------------------------------------------------------------------------------------

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Posted (edited)

Another conversion. :)
If the parameter $iThickness = 0 then Creates a filled rectangle

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIDlg.au3>
#include <WinAPIGdi.au3>

Local $aInput[11]
$aInput[0] = 10

Local $Form1 = GUICreate("Form1", 286, 165, 853, 226)
GUISetFont(11)
; Create Input
Local $iX = 10, $iY = 10
For $i = 1 To $aInput[0]
    $aInput[$i] = GUICtrlCreateInput(Random(-100, 100, 1), $iX, $iY, 121, 21)
    $iY += 30
    If $i = 5 Then
        $iX = 150
        $iY = 10
    EndIf
Next
GUISetState(@SW_SHOW)

;**********************************
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    GetActiveInput($Form1)
WEnd
;**********************************

;--------------------------------------------------------------------------------------------------------------------------------
Func GetActiveInput($hGUI)
    Local Static $LastCtrl, $hFrame[2] = [0, 1], $ia = 1  ;= GetActiveGUICtrl($hGUI)
    Local $ActiveCtrl = GetActiveGUICtrl($hGUI)

    If $LastCtrl <> $ActiveCtrl And $ActiveCtrl > 0 Then
        $LastCtrl = $ActiveCtrl
        Local $aCtrl, $aWnd
        $aCtrl = ControlGetPos($hGUI, "", $ActiveCtrl)
        $hFrame[$ia] = _GuiFrame("123Frame", $aCtrl[0], $aCtrl[1], $aCtrl[2], $aCtrl[3], 0, 0x00FFFF, 50, $hGUI, True, 1)
        $ia += 1
        If $ia > 1 Then $ia = 0
        If $hFrame[$ia] Then GUIDelete($hFrame[$ia])
    EndIf

EndFunc   ;==>GetActiveInput
;--------------------------------------------------------------------------------------------------------------------------------
Func GetActiveGUICtrl($hGUI)
    Return _WinAPI_GetDlgCtrlID(ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)))
EndFunc   ;==>GetActiveGUICtrl

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _GuiFrame
; Description....: Creates a rectangle frame or a filled rectangle
; Syntax.........: _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom [, $iThickness = 1 [, $iColor = 0xFF0000 [, $iTransparency = 150 [, $hWndParent = 0 [, $MDICHILD = False [, $iFlag = 0 ]]]]]])
; Parameters.....: $sTitle        - The title of frame.
;                  $iLeft         - The left coordinate of frame.
;                  $iTop          - The top coordinate of frame.
;                  $iRight        - The right coordinate of frame.
;                  $iBottom       - The bottom coordinate of frame.
;                  $iThickness    - [optional] The thickness of frame (default = 1). If $iThickness = 0 Creates a filled rectangle
;                  $iColor        - [optional] The color of frame (default = 0xFF0000).
;                  $iTransparency - [optional] The transparency of frame, in the range 1 - 255 (default = 150).
;                  $MDICHILD      - [optional] Create as child, that will be moved with parent  (default = False).
;                  $hWndParent    - [optional] The parent window handle (default = 0).
;                  $iFlag         - [optional] $iFlag=0 $iRight=$iRight and $iBottom=$iBottom (default = 0).
;                                              $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
; Return values..: The handle of the created frame.
; Author ........: ioa747
; Notes .........: Note that coordinate, are the internal frame dimensions.
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _GuiFrame($sTitle, $iLeft, $iTop, $iRight, $iBottom, $iThickness = 1, $iColor = 0xFF0000, $iTransparency = 150, _
        $hWndParent = 0, $MDICHILD = False, $iFlag = 0)

    If $iThickness = -1 Or $iThickness = Default Then $iThickness = 1
    If $iColor = -1 Or $iColor = Default Then $iColor = 0xFF0000
    If $iTransparency < 1 Or $iTransparency = Default Or $iTransparency > 255 Then $iTransparency = 150
    Local $iWidth, $iHeight

    If $iFlag = 1 Then ; $iFlag=1 $iRight=$iWidth and $iBottom=$iHeight
        $iWidth = $iRight + (2 * $iThickness)
        $iHeight = $iBottom + (2 * $iThickness)
    Else
        $iFlag = 0
        $iWidth = $iRight - $iLeft + (2 * $iThickness) + 1
        $iHeight = $iBottom - $iTop + (2 * $iThickness) + 1
    EndIf
    Local $ExStyle
    If $hWndParent <> 0 And $MDICHILD = True Then
        $ExStyle = BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE, $WS_EX_MDICHILD, $WS_EX_TRANSPARENT)
    Else
        $ExStyle = BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE, $WS_EX_TRANSPARENT)
    EndIf
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft - $iThickness, $iTop - $iThickness, _
            $WS_POPUP, $ExStyle, $hWndParent)

    GUISetBkColor($iColor, $hGUI)
    WinSetTrans($hGUI, "", $iTransparency) ;255 = Solid, 0 = Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

    If $iThickness > 0 Then
        Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn
        $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $iWidth, $iHeight)
        $hInner_rgn = _WinAPI_CreateRectRgn($iThickness, $iThickness, $iWidth - $iThickness, $iHeight - $iThickness)
        $hCombined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
        _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF)
        _WinAPI_DeleteObject($hInner_rgn)
        _WinAPI_SetWindowRgn($hGUI, $hCombined_rgn)
    EndIf
    Return $hGUI
EndFunc   ;==>_GuiFrame
;--------------------------------------------------------------------------------------------------------------------------------

 

Edited by ioa747
correction

I know that I know nothing

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